字段类型不完整
Field has incomplete type
template <class Type>
class Punct {
protected:
Type _x; // (1)
Type _y; // (1)
public:
Punct(Type = 0, Type = 0); // (2)
~Punct();
inline Type getX() const { return _x; }
inline Type getY() const { return _y; }
inline void setX(Type x) { _x = x; }
inline void setY(Type y) { _y = y; }
inline void moveBy(int x, int y) { _x = x; _y = y; }
friend std::istream &operator>>(std::istream&ins, Punct<Type>& A);
friend std::ostream &operator<<(std::ostream&outs, const Punct<Type>& A);
};
这些是我得到的错误:
(1) -字段有不完整类型' type '
(2) -没有可行的从int到type的转换(有些添加3)。(此处传递参数给形参)
你能告诉我我做错了什么吗?
这段代码适合我。g++ 4.7.2
on Kubuntu 12.04
.
顺便说一下,您是否将Punct
类的所有实现都放在一个文件中,即头文件,或者您将它们分开到.h
和.cpp
中?
#include <iostream>
using namespace std;
template <class Type>
class Punct {
protected:
Type _x; // (1)
Type _y; // (1)
public:
Punct(Type = 0, Type = 0) {}; // (2) <- empty function body added
~Punct() {}; // <- empty function body added
inline Type getX() const { return _x; }
inline Type getY() const { return _y; }
inline void setX(Type x) { _x = x; }
inline void setY(Type y) { _y = y; }
inline void moveBy(int x, int y) { _x = x; _y = y; }
template<class T> // <- added
friend std::istream &operator>>(std::istream&ins, Punct<T>& A);
template<class T> // <- added
friend std::ostream &operator<<(std::ostream&outs, const Punct<Type>& A);
};
// bogus function added
template<class T>
istream &operator>> (istream &i, Punct<T> &a)
{
return i;
}
// bogus function added
template<typename T>
ostream &operator<< (ostream &i, const Punct<T>& a)
{
return i;
}
int main()
{
Punct<int> a;
}
相关文章:
- 将结构字段的类型展开为可变模板参数
- 结构体和类的不同大小(),彼此具有相同的字段类型
- 错误:字段'dateOfBirth'的类型不完整'Poco::Data::Date'
- 获取具有字段名称的 SELECT 字段类型,并带有 MariaDB C++连接器
- 无法初始化以 std::byte 作为成员类型的位字段
- 无法访问 Arduino 结构字段。错误"退出状态 1。xxxx 不命名类型"
- 在这种情况下,如何从类型 "const char*" 初始化字段?
- 确定输入"conscalc: calc"的类型时出错。不能联合编码器。具有不同字段集的结构类型
- 字段在正向声明中具有不完整的类型
- 使用固定大小类型时强制对位字段(C++14 之前)进行签名
- 返回对位字段的访问类型
- 将枚举类型保存在位字段 [dcl.enum] [class.bit] 中
- 将指向结构的指针转换为具有较少字段数的另一种结构类型
- 位字段成员的类型
- 无法汇总初始化类型结构的变量,其中包含在类模板中的位字段成员
- 在相同类型的字段上迭代
- Boost Xpressive-字段“ M_RX”具有不完整的类型
- 设计具有变体字段的文本类型类,其中可以存储一个或三个对象
- 自动复制=按值并支持多态性的适当类型的非静态字段
- 在std::set/std::map中存储具有多个不同类型字段的c++对象的有效方法