C 模板 - 主要表达式
C++ Template - primary expression needed
错误在使用gcc/g 编译器在cygwin环境下编译以下程序 -/src/template_1.cpp:66:2:错误:"模板"之前预期的主要表达 模板TemplateCall :: TemplateCall; ^
我的源代码如下: -
#include<iostream>
#include<cstdarg>
using namespace std;
template<class T>
class TemplateCall
{
private:
T dataValue;
public:
TemplateCall(T somethingValue);
void showTTParam();
};
template<class T>
TemplateCall<T>::TemplateCall(T somethingValue)
{
cout << endl << " Calling TemplateCall - constructor " << endl;
dataValue = somethingValue;
}
template<class T>
void TemplateCall<T>::showTTParam()
{
cout << endl << " TemplateTemplateParam - showTTParam " << endl;
cout << endl << " dataValue - showTTParam " << dataValue << endl;
}
int main()
{
template TemplateCall<int>;
return 0;
}
要创建一个TemplateCall<int>
实例,您需要使用:
TemplateCall<int> obj;
更新,响应OP的评论
要明确实例化类模板,请使用
template class TemplateCall<int>;
但是您需要在所有功能之外使用它。
相关文章:
- 表达式模板玩具示例:用户定义的强制转换不适用于复杂类型
- 折叠表达式模板参数推导/替换失败
- 表达式模板需要冗余重载
- 在语法树中的节点上定义的层次结构的表达式模板
- C++表达式模板不明确的运算符重载
- 如何将表达式模板用于特定类型
- 使用表达式模板编译时间数组索引--constexpr
- 令牌调用之前'...'预期的主表达式 模板化类的模板化方法
- 包装内部函数的简单C++表达式模板会产生不同的指令
- c++矩阵与表达式模板问题
- 为什么 std::basic_string 不支持通过表达式模板进行串联?
- 如何围绕表达式模板编写第三方库包装类
- 表达式模板和 C++11.
- 表达式模板:错误 C2784 'could not deduce template argument'
- 表达式模板实现未优化
- 使用自动关键字创建的类型的表达式模板中存在分段错误
- 令人困惑的表达式模板与 O3 的隔离错误
- 分析表达式模板
- 表达式模板 - 无法专用化函数模板
- 表达式模板的核心功能:赋值运算符子模板类型