标题:救救孩子吧
取消只看楼主
牛雅杰
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2021-8-3
结帖率:100%
已结贴  问题点数:20 回复次数:0 
救救孩子吧
实在不知道怎么回事,就是不能实现不输类型运行,模板类型不是可以自动识别吗?
程序代码:
#include <iostream>
using namespace std;
template<class T>
class sring{
    public:
    T data;
    constexpr sring(T d):data(d){}
};

int main(){
    sring a=1;
    cout<<a.data;
}

结果是这样,gcc,windows上
程序代码:
c:\c++>g++ shiyan.cpp
shiyan.cpp: In function 'int main()':
shiyan.cpp:18:11: error: missing template arguments before 'a'
     sring a=1;
           ^
shiyan.cpp:19:11: error: 'a' was not declared in this scope
     cout<<a.data;
搜索更多相关主题的帖子: class cpp 孩子 main data 
2021-08-03 20:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-506391-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.436019 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved