I am trying to initialize a member of a class in which the member is an instance of another class. Visual Studio seems like I'm declaring a member of a function:
class OtherClass {
OtherClass();
OtherClass(string Foo);
}
class MainClass {
OtherClass Instance1;
OtherClass Instance2("Foobar");
}
I understand that I can accomplish what I want with a member initialization list, for example:
class MainClass {
OtherClass Instance2;
MainClass() : Instance2("Foobar") {}
}
I am simply confused by the fact that in the first example, the compiler understands that I initialize the NewClass member when I use the default constructor, but he thinks that I declare the function if I try to use the constructor that expects the string. Can someone explain the explanation for this and if there is another problem that I don't know about?
Update: This declaration ambiguity is named: Most Vexing Parse