本文介绍了C ++无效使用非静态数据成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发C ++应用程序,但出现错误无效使用非静态数据成员C ++
.我已经发布了所有与错误相关的代码.如果有人能指出我的愚蠢,我将不胜感激.谢谢!
I'm developing c++ application there I'm getting the errorInvalid use of non-static data member C++
. I have posted all the code which is related The error. I would be very grateful if anyone could point out my stupidity. Thanks!
Const2DCDP.h
Const2DCDP.h
class Const2DCDP{
public:
int *ex;
};
2DCPDP4.h
2DCPDP4.h
#include "Const2DCDP.h"
class CDP{
}
2DCPDP4.cpp
2DCPDP4.cpp
#include "2DCDP4.h"
void CDP::Release()
{
if(Const2DCDP::ex != NULL){ // Invalid use of non static data //member 'ex'
free(ex);
ex = NULL;
}
}
推荐答案
您正在使用的数据成员( ex
)不是静态成员.因此,不能在类名称上调用它,您需要一个类 instance 才能使用它.
The data member (ex
) you are using is not a static member. So it cannot be called on the class name, you need a class instance to use it.
这篇关于C ++无效使用非静态数据成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!