+ 2

C++ function that don't have access modifier

hi im new in c++. before learning c++ i am java programmer, but im still beginner in java... how to write c++ function that doesn't have access modifier like public private etc. after create some function that have access modifier ? in java: public void hello1() { ... } void hello2() { ... } // this doesn't have access modifier in c++: public: void hello1() { ... } // this is public void hello2() { ... } // too //after i write "public:", all function below "public:" is public sorry bad english, thanks.

2nd Jan 2021, 8:15 AM
Yousef Ady
Yousef Ady - avatar
1 ответ
+ 3
Yousef Ady #include <iostream> using namespace std; class Example { public: void hello1() { cout << "Hello"; } }; int main() { Example obj; Example* ex; //used pointer to make an object ex = &obj; assigned address of obj to avoid warning ex->hello1(); return 0; } Same like above do for hello2
2nd Jan 2021, 8:47 AM
A͢J
A͢J - avatar