If you want to define a function inside a class, the most general syntax looks like:
class Object { int property; void doSomething() { property=100; } };
If you want to define a function outside , it is similar to declaring functions in front of the main and in library files. In your class, you have:
class Object { int property; void doSomething(); };
Then, somewhere after your class, after the main () function or in the included file, you can determine:
void Object::doSomething() { property=100; }
Some classes are places in the header file and definitions in the cpp file used by this header. Various methods are possible.
Both of these approaches are valid. Often I will include very small and / or basic class functions directly in the class and other functions that do the harder work that I usually share. Try to think about the difference in coming to your code and want to change it.
Garet claborn
source share