How do I define a function inside of a class using C++?
+13
A:
There are 2 answers:
1) Combining both the declaration and the definition:
class C
{
public:
//declaration and definition of f
void f()
{
}
};
2) Separating the declaration and the definition:
class C
{
public:
//declaration of f
void f();
};
//definition of f
void C::f()
{
}
Typically in option #2 you would separate the declaration into a header file and the definition inside a source file.
Brian R. Bondy
2010-02-22 02:00:59
That's the answer (+1). May as well accept it; no one will post any more, because that covers it all.
Mawg
2010-02-22 02:23:33
This is perfect if I could give you plus 10 I would :) tyvm
H4cKL0rD
2010-02-22 03:06:34