Maxpm
Maxpm

Reputation: 25592

Syntax for Function Prototyping in Header Files

Consider I have the following function prototype:

void MyFunction(int MyParameter);

With the following definition:

void MyFunction(int MyParameter)
{
    // Do stuff here.
}

Where should they each be put if I have a header file (no main function) with a namespace? Does the prototype go in the namespace and the definition outside it? Or do they both go in?

Upvotes: 0

Views: 4414

Answers (3)

Xavier V.
Xavier V.

Reputation: 6488

If you choose to have a namespace, both should be inside :

.h :

namespace MyNameSpace {
void MyFunction(int MyParameter);
}

.cpp :

void MyNameSpace::MyFunction(int MyParameter)
{
    // Do stuff here.
}

Upvotes: 2

wkl
wkl

Reputation: 80001

If your prototype is not in the namespace, then you do not have to put the definition in the namespace. If the prototype is in a namespace, the definition should be in the same namespace.

Upvotes: 1

ognian
ognian

Reputation: 11541

They both have to be in the namespace

Upvotes: 0

Related Questions