It's been a long time since I programmed in C++ and so I am a little puzzled.
Looking at some old code of mine I see that I have in a .h file a declaration of a class called Date.
In another file, the .cpp, I declare the constructor, destructor, methods, etc.
I define the constructors as:
Date::Date() : _year(0), _month(0), _day(0)
{}
My question is why is there a Date:: infront? Is a class name automatically a namespace? Is this necessary only because I decided to separate the definitions into the .cpp and leave the declaration in the .h?
The reason why this is an issue is because I'm writting a C# wrapper as a .DLL and invoking the C++ class from C# throught the wrapper and I think the qualifier Date:: is not understood in the C# wrapper.
If I'm not wrong, every class has its own name space so if you want to define (out of the class declaration) its methods you must use Date:: to tell the compiler that you're implementing the methods of the class Date.
For example, consider the following fragment of code:
1 2 3 4 5 6 7 8 9 10
class A
{
public:
void foo ();
};
void foo ()
{
// ...
}
In the previous example, the definition of foo () corresponds to a global function, it isn't the implementation of the foo () method of the class Date. You must tell the compiler that you are providing an implementation of the foo () method by using the :: operator.