This question deals with unmanaged C++ (Visual Studio 2005).
Suppose I have a class named MyClass with a constructor that takes an
argument. How do I create an instance of type MyClass as a member variable
(see below)?
Class Test
{
public:
Test(void); // Constructor
~Test(void); // Destructor
private:
MyClass m_myClass("My argument"); // error C2059; syntax error :
'constant'
};
TIA - Bob
>Suppose I have a class named MyClass with a constructor that takes an
>argument. How do I create an instance of type MyClass as a member variable
[quoted text clipped - 10 lines]
>'constant'
> };
Bob,
I think you'd do it like this:
Test() : m_myClass( "Hello" )
{
}
private:
MyClass m_myClass;
Dave
Bob Altman - 25 Jun 2007 21:19 GMT
Thanks!
- Bob
> >Suppose I have a class named MyClass with a constructor that takes an
>>argument. How do I create an instance of type MyClass as a member
[quoted text clipped - 24 lines]
>
> Dave