English 中文(简体)
无法在其它类中创建类对象吗?
原标题:Not able to create a class object inside another class?
  • 时间:2012-05-26 15:06:51
  •  标签:
  • visual-c++

我有一个无法在其它类中创建类对象的假想。 假想如下:

class base
{
public:
base();
~base();
int getbase(void){return baseVar;}
void setbase(int arg){baseVar = arg;}
private:
int baseVar;
};

class derived1 : public base
{
public:
derived1();
~derived1();
int getbase(void);
void setbase(int arg);
private:
int derVar1;
};

class derived2 : public base
{
public:
derived2();
~derived2();
int getbase(void);
void setbase(int arg);
private:
int derVar2;
};

class container
{
public:
container();
~container();

derived1 derObj1;
derived2 derObj2;

private:
int containerVar;
};

class usage
{
public:
usage();
~usage();
private:
container containerObj; // compilation error
int usegeVar;
};

compilation error is : error C2146: syntax error : missing ; before identifier containerObj error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C4430: missing type specifier - int assumed. Note: C++ does not support default-int i am using vc++

我请求一些人如何纠正这一汇编错误?

问题回答

复制一个已粘贴的代码到一个空的视觉C++ 2k8 工程上, 已经确定!





相关问题
how to reliable capture display setting changed

static void Main() { // Set the SystemEvents class to receive event notification when a user // when display settings change. SystemEvents.DisplaySettingsChanged += new ...

Why use CComBSTR instead of just passing a WCHAR*?

I m new to COM. What exactly is the advantage of replacing: L"String" with CComBSTR(L"String") I can see a changelist in the COM part of my .NET application where all strings are replaced in this ...

COM Basic links

folks can you provide me the tutorial link or .pdf for learning basic COM?. i do google it.. still i recommend answers of stackoverflow so please pass me.. Thanks

Statically linking Winsock?

I m using Winsock 1.1 in my project. I include wsock32.lib in "Additional Dependencies". I m looking at the DLL project using depends.exe and notice that the DLL depends on wsock32.dll. How can I ...

热门标签