0
class obj1{
public:
void do(){}
void some(){}
void stuff(){}
};
class obj2{
public:
void nowDo(){}
void someOther(){}
void things(){}
};
template <class T>
class structure{
public:
/*
access public members of Ts's elements while encapsulating the vector
(preferably without copying all of obj's public members in the structure)
*/
private:
vector <T *> Ts;
};
void foo(){
structure <obj1 *> str1;
structure <obj2 *> str2;
/*
Access public members of str1 and str2's elements
*/
}
'구조'템플릿 클래스 내에 해당 벡터를 캡슐화하면서 'obj'요소의 public 멤버에 액세스 할 수있는 방법이 있습니까?캡슐화 된 벡터에서 요소의 공용 멤버에 액세스하는 방법은 무엇입니까?
'구조체'를 균질 한 템플릿 클래스로 만들고 싶기 때문에 '구조체'의 'obj'public 멤버를 모두 복사하지 않고 선호합니다. 이렇게하면 고유 한 데이터를 만들 필요가 없습니다. 내가 포함하고 싶은 모든 객체의 구조.
당신은 불필요한 일을'이 *'. 템플릿에 대한 인수 또는 벡터 정의 중 하나. 어쨌든 귀하의 질문은 너무 광범위합니다. 다양한 장소에서 회원에게 액세스하는 데는 여러 가지 방법이 있습니다. – StoryTeller
또한,'struct'는'class'가 아닙니다 – Jerfov2
오버로드 된 연산자 []'? – Quentin