模板类定义类型

Template class define type

本文关键字:类型 定义      更新时间:2023-10-16

对于个人项目,我需要定义一个模板类以获得更好的优化。

我已经遵循了示例,但它还没有编译,因为我希望我的模板类从接口继承。有人可以告诉我如何使用它,这是我的代码:

我的点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

()