tags:

views:

103

answers:

1

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
That's the answer (+1). May as well accept it; no one will post any more, because that covers it all.
Mawg
This is perfect if I could give you plus 10 I would :) tyvm
H4cKL0rD