我创建了一个名为Chromosome的类,最终只是用vector来包装一个ostream运算符,所以我决定使用typedef vector代替。然而,我在模板化的ostream运算符方面遇到了麻烦...这是最好的方法吗?(我看过一些方法,但都无法成功)
template<typename G>
class Chromosome {
public:
typedef typename std::vector<G> type;
typedef typename std::pair<type *,type *> ptr_pair;
};
template<typename G> //line 19 below:
std::ostream& operator<<(std::ostream& os, const Chromosome<G>::type& chromosome) {
for(auto iter = chromosome.begin(); iter != chromosome.end(); ++iter)
std::cout << *iter;
return os;
}
目前我遇到的错误是:
。
chromosome.h:19: error: expected unqualified-id before ‘&’ token
chromosome.h:19: error: expected ‘)’ before ‘&’ token
chromosome.h:19: error: expected initializer before ‘&’ token
干杯。