模板类定义类型
Template class define type
对于个人项目,我需要定义一个模板类以获得更好的优化。
我已经遵循了示例,但它还没有编译,因为我希望我的模板类从接口继承。有人可以告诉我如何使用它,这是我的代码:
我的点HPP
template<typename T>
class Container : public IOP
{
public:
Container();
T val;
int getpr() const;
IOP *operator+(const IOP &r) const;
IOP *operator-(const IOP &r) const;
IOP *operator*(const IOP &r) const;
IOP *operator/(const IOP &r) const;
}
我的点 cpp 那里有我的函数(构造函数...
Container::Container()
{
}
int Container::getpr()
{
...
}
... etc
我想像这样使用我的类:
Container<long> test;
或
Container<int> test;
感谢您的任何帮助,链接或解释。
目前的编译错误:
Container.cpp:13:1: error: expected a class or namespace
Container::Container()
^
Container.cpp:13:12: error: C++ requires a type specifier for all declarations
Container::Container()
~~~~~~~~~ ^
Container.cpp:24:20: error: expected a class or namespace
std::string const &Container::toString()
^
Container.cpp:29:5: error: expected a class or namespace
int Container::getPrecision
()
不要忘记提到
template <class T>
Container<T>::Container()
{
}
template <class T>
int Container<T>::getpr()
{
...
}
因为在您的代码中,这意味着您有模板类 Container
相关文章:
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- 强枚举类型定义:Clang Bug 还是 C++11 标准不确定性?
- 列表参数的类型定义
- 使用模板化的键类型定义 std::map,该键类型基于作为参数接收的函数
- 关于 C++ 中的函数类型定义
- C++(和 ROS) - 包含与前向声明引用,设置默认值和类型定义
- 将使用/类型定义限制为类范围
- 模板类型定义?
- C++:模板类的类型定义
- 如何对命名空间限定类型进行类型定义?
- 此递归模板类型定义是否有效C++?
- 具有调整对齐方式的类型定义
- C++从抽象类型定义类成员
- 用于C++代码的 API 监视器类型定义 (XML)
- 如何将result_of与函数类型定义一起使用
- 在C++的适当类型定义位置
- 如何根据模板类型定义浮点常量?
- 如何为缺少预定义运算符而不扩展命名空间"std"的标准类型定义运算符>> (istream &, ...)?
- 参数化类的别名(或类型定义)内部类
- 如果我想从类型"T"定义元素的容器(来自 STL),那么"T"必须使用默认构造函数?