하자가클래스 내부에있는 구조체를 얻는 방법은 무엇입니까?
class A{
public:
struct stuff{
int x;
int y;
};
stuff get_stuff(int index){
if(index < vec_stuff.size() && index >= 0) return vec_stuff[index];
else return nullptr;
}
std::vector<stuff> vec_stuff;
};
내가 적절하게 그 vec_stuff
를 채울 가정 내가 클래스가 말한다.
그런 다음 다른 클래스
#inclde "A.h"
class B{
public:
B(){}
void f(int index, int k){
xxxx = a.get_stuff(index)
}
A a; // assume A is initialized properly
}
그래서 나는 그것이 struct stuff
해야이 xxxx
를 쓴 장소 그러나 나는이 작업을 수행 할 때 내가 컴파일러을 어떻게 그래서 use of undeclared identifier
을 얻을에서 내가 말하는거야 stuff
는 것을 알고 A. 내부
'else return nullptr;'HUH ?? –
'자동 '입니까? ------- – Quentin
@WhiZTiM 아니면'auto xxxx = a.get_stuff (index);'. 이것은'private '중첩 된 구조체로도 작업 할 수 있다는 장점이 있습니다. –