我有一个名为Nuage的类(它是Points的集合),在这里我将使用Vector类的功能来操纵该类。nuage.cpp文件是:
#include <iostream>
#include "nuage.hpp"
template <typename T>
Nuage<T>::Nuage(){}
template <typename T>
void Nuage<T>::ajouter(const T& p) {
v.push_back(p);
}
template <typename T>
unsigned int Nuage<T>::size() const {
return v.size();
}
template <typename T>
const_iterator Nuage<T>::begin() const{
return v.begin();
template <typename T>
Nuage<T>::~Nuage(){}
nuage.hpp是:
#ifndef NUAGE_HPP
#define NUAGE_HPP
#include <cstdlib>
#include <sstream>
#include <vector>
template <typename T>
class Nuage {
private:
std::vector<T> v;
public:
using const_iterator = typename std::vector<T>::const_iterator;
Nuage();
void ajouter(const T&);
unsigned int size() const;
const_iterator begin() const;
~Nuage();
};
#endif
我有一个错误说:
error: ‘const_iterator’ does not name a type; did you mean ‘constexpr’?
错误在这一行: const_iterator Nuage<T>::begin() const{
有人可以帮我找到它吗?谢谢
采用
template <typename T>
typename Nuage<T>::const_iterator Nuage<T>::begin() const{
return v.begin();
}
当编译器处理您的.cpp
文件时,您引用的类型const_iterator
不存在。仅Nuage<T>::const_iterator
存在。容易监督。
在typename
需要的关键字怎么一回事,因为Nuage<T>::const_iterator
是一个从属名称。需要告诉编译器此表达式是类型,而不是静态变量或函数或类内的其他内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句