I am stubbing the class "myClass" and its 50+ members "myMemberFunction*" for a unit test.
I don't want to write the class name every time, so I tried the following:
namespace myNamespace{
myClass::myClass()
{
// constructor code
}
namespace myClass {
void myMemberFunction1()
{
// function 1 code
}
void myMemberFunction2()
{
// function 2 code
}
}
}
When compiling I get the error "myClass has already been declared in the current scope". However, the following works:
namespace myNamespace{
myClass::myClass()
{
// constructor code
}
void myClass::myMemberFunction1()
{
// function 1 code
}
}
Is there a way I do not have to write "myClass::" before every function stub? How am I misunderstanding namespaces?
Classes and namespaces are two different things. You cant use namespace myClass
and define all the members inside. You have to use <return type> myClass::<function>
every time you define it outside the class.
You could use tools like Visual Assist, Intellisense to create the function definitions for you. But apart from that, you cannot use classes like namespaces. Another alternative is to define the functions inside the class body itself. This might be problematic each time you edit the class because then all the source files which use your class header file will get recompiled.
References: MSDN documentation