In C++, what's the benefit of having a class with functions...
say
class开发者_如何学JAVA someClass{
public:
void someFunc(int arg1);
};
then having the function's actual functionality declared after int main
int main()
{ return 0; }
void someClass::someFunc(int arg1)
{ cout<<arg1; }
Furthermore, what's the benefit of declaring the class in a .h header file, then putting the functionality in a .cpp file that #includes the .h file?
Dependency management. Users of the class only need to include the header file, so they don't depend on the implementation.
Another use is breaking circular dependencies.
Both issues may look like a waste of time with toy programs, but they start to grow into a really bad problem as the program grows.
精彩评论