在访问数据时遇到问题 [英] Getting problems in accessing the data
本文介绍了在访问数据时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
class X
{
public:
int Data;
};
class Y : public X
{
public:
};
class Z
{
public:
static Y y;
};
class myClass
{
public:
void myRoutine()
{
cout<<Z::y.Data;
}
};
int main()
{
myClass cls;
cls.myRoutine();
_getch();
return 0;
}
此错误->
this Error->
1>experiment.obj : error LNK2001: unresolved external symbol "public: static class Y Z::y" (?y@Z@@2VY@@A)
1>C:\temp projs\experiment\Debug\experiment.exe : fatal error LNK1120: 1 unresolved externals
该代码不起作用.唐诺为什么..? :(
帮助我..
This code is not working. donno why..? :(
help me..
推荐答案
将数据设为静态有什么用?
what about making the Data as static?
class X
{
public:
static uint32_t Data;
};
改进后,您必须在基类的基础上提及public. (If you do not choose an inheritance type, C++ defaults to private inheritance
)
Improved, you have to mention public where inhering from the base class. (If you do not choose an inheritance type, C++ defaults to private inheritance
)
class Y : public X
{
public:
};
类的静态成员必须初始化:
Static members of a class must be initialized:
Y Z::y;
int main()
{
...
这篇关于在访问数据时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文