아직 포인터와 참조를 잘 이해하지 못하고 있지만 정적 메서드와 변수가있는 클래스가 있으며 기본 클래스와 다른 클래스에서 참조됩니다. main()에 정의 된 변수가 있습니다. 정적 함수를 사용하여이 클래스의 변수에 전달하려고합니다. 이러한 함수가 main() 범위에서 볼 수있는 변수의 값을 변경하기를 원합니다.정적 포인터가있는 C++ 클래스
//foo.h
class foo
{
public:
static int *myPtr; //its just a declaration, not a definition!
bool somfunction() {
*myPtr = 1;
//where is return statement?
}
}; //<------------- you also forgot the semicolon
/////////////////////////////////////////////////////////////////
//foo.cpp
#include "foo.h" //must include this!
int *foo::myPtr; //its a definition
:
이것은 내가 뭘하려고 오전의 예입니다,하지만 난 컴파일러 오류를 얻을 ...
class foo
{
public:
static int *myPtr;
bool somfunction() {
*myPtr = 1;
return true;
}
};
int main()
{
int flag = 0;
foo::myPtr = &flag;
return 0;
}
일반적으로 컴파일러 오류가 발생할 때마다 _always_가 질문에이를 포함시킵니다. –