c++ - 我可以使用类模板返回类型的函数吗?

标签 c++ class templates

<分区>

只是想向各位专业人士请教一个简单的问题! 我实现了如下代码的模板类:

template <typename T>
class Matrix { ... };

我正在尝试使用具有返回类型的函数作为类模板。

Matrix<double> get_some_matrix(int param1,int param2) {...};

不幸的是,编译器生成如下错误消息:Error C2143 : missing ';'在 '<'

之前

谁能告诉我或猜出问题出在哪里?

非常感谢您的帮助,非常感谢!

最佳答案

template <typename T>
class Matrix { ... } //missing ; at end of class declaration.

应该是:

template <typename T>
class Matrix { ... };  // note ;

关于c++ - 我可以使用类模板返回类型的函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15389425/

相关文章:

在共享内存数组中使用 std::string 时的 c++ 内存泄漏

python : tracking change in class to save it at the end

jquery - 为具有相同类别的 div 随机添加类别

c++ - 运行时函数模板类型推导

c++ - 将 "int"添加到 "uint_64t"

c++ - Voro++可以在Visual Studio中编译吗

c++ - ffmpeg YUV420 到 RGB24 只转换一行

iOS SDK - 与 socket 建立连接的正确方法?

c++ - 有没有办法通过数组类型专门化函数模板?

c++ - 通过模板传递成员函数指针