업데이트 : 수정 된 것 같습니다. 고마워요!C++ : 오류 : 유효하지 않은 이름 사용
오류가 발생했습니다. 알아낼 수 없습니다. 는이 코드가 다음 줄에
//A Structure with one variable and a constructor
struct Structure{
public:
int dataMember;
Structure(int param);
};
//Implemented constructor
Structure::Structure(int param){
dataMember = param;
}
//A class (which I don't plan to instantiate),
//that has a static object made from Structure inside of it
class unInstantiatedClass{
public:
static Structure structObject;
};
//main(), where I try to put the implementation of the Structure from my class,
//by calling its constructor
int main(){
//error on the line below
Structure unInstantiatedClass::structObject(5);
return 0;
}
말한다 "구조 unInstantiatedClass :: structObject (5);"나는라는 오류 얻을 :
error: invalid use of qualified-name 'unInstantiatedClass::structObject'
나는이 오류 봤 한을 몇 개의 포럼 게시물을 살펴 보았지만 모두의 문제는 다른 것처럼 보입니다. 나는 또한 "클래스 내 정적 구조체 개체"및 기타 관련 구를 인터넷 검색을 시도했지만 정말 내 문제와 관련 있다고 생각되는 것을 발견하지 못했습니다.
내가 여기서하려고하는 것은 : 내가 인스턴스화하지 않은 수업이 있습니다. 그 클래스 안에는 생성자를 통해 설정할 수있는 변수가있는 정적 객체가 있습니다.
도움을 주시면 감사하겠습니다. 감사.
아니요, 이미 인스턴스이고 초기화 된 상태입니다. 정적이라는 것을 알 수 있습니다. –
컴파일러가 없어도 똑같은 오류가 나옵니까? 문제는 정의가 함수 내부에있을 수 없으며 초기화 스타일을 직접 복사로 변경해도 차이가 발생하지 않는다는 것입니다. –
동의합니다. 정적 멤버 초기화를 전역 범위로 이동해야합니다. – Tuxdude