| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 676 人关注过本帖
标题:程序改错~关于类模板的提问
取消只看楼主 加入收藏
S140131022
Rank: 2
来 自:重庆邮电大学
等 级:论坛游民
帖 子:205
专家分:35
注 册:2014-10-9
结帖率:90.24%
收藏
 问题点数:0 回复次数:1 
程序改错~关于类模板的提问
#include<iostream>
using namespace std;

template<class numtype>
class Compare
{
public:
    Compare(numtype,numtype);
    numtype min();
    numtype max();
private:
    numtype a;
    numtype b;
};

Compare::Compare(numtype a1,numtype b1):a(a1),b(b1){};

numtype Compare::max()
{
    return a>b?a:b;
}

numtype Compare::min()
{
    return a<b?a:b;
}

int main()
{
    Compare<int> cmp(3,5);
    cout<<"max="<<cmp.max()<<endl;
    Compare<float> cmp1(6.6,8.8);
    cout<<"min="<<cmp1.min()<<endl;
}

//这个程序错在哪儿! 求大神修改~
搜索更多相关主题的帖子: private include public return 
2015-09-21 10:24
S140131022
Rank: 2
来 自:重庆邮电大学
等 级:论坛游民
帖 子:205
专家分:35
注 册:2014-10-9
收藏
得分:0 
一下是编译信息:

Compiling...
Cpp1.cpp
C:\Users\123\Desktop\practice 5\Cpp1.cpp(16) : error C2955: 'Compare' : use of class template requires template argument list
        C:\Users\123\Desktop\practice 5\Cpp1.cpp(14) : see declaration of 'Compare'
C:\Users\123\Desktop\practice 5\Cpp1.cpp(16) : error C2955: 'Compare' : use of class template requires template argument list
        C:\Users\123\Desktop\practice 5\Cpp1.cpp(14) : see declaration of 'Compare'
C:\Users\123\Desktop\practice 5\Cpp1.cpp(16) : error C2065: 'numtype' : undeclared identifier
C:\Users\123\Desktop\practice 5\Cpp1.cpp(16) : error C2146: syntax error : missing ')' before identifier 'a1'
C:\Users\123\Desktop\practice 5\Cpp1.cpp(16) : error C2350: 'Compare::Compare<numtype>::Compare<numtype>' is not a static member
C:\Users\123\Desktop\practice 5\Cpp1.cpp(16) : error C2059: syntax error : ')'
C:\Users\123\Desktop\practice 5\Cpp1.cpp(16) : error C2065: 'a1' : undeclared identifier
C:\Users\123\Desktop\practice 5\Cpp1.cpp(16) : error C2501: 'a' : missing storage-class or type specifiers
C:\Users\123\Desktop\practice 5\Cpp1.cpp(16) : error C2065: 'b1' : undeclared identifier
C:\Users\123\Desktop\practice 5\Cpp1.cpp(16) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
C:\Users\123\Desktop\practice 5\Cpp1.cpp(18) : error C2955: 'Compare' : use of class template requires template argument list
        C:\Users\123\Desktop\practice 5\Cpp1.cpp(14) : see declaration of 'Compare'
C:\Users\123\Desktop\practice 5\Cpp1.cpp(18) : error C2955: 'Compare' : use of class template requires template argument list
        C:\Users\123\Desktop\practice 5\Cpp1.cpp(14) : see declaration of 'Compare'
C:\Users\123\Desktop\practice 5\Cpp1.cpp(18) : error C2143: syntax error : missing ';' before 'tag::id'
C:\Users\123\Desktop\practice 5\Cpp1.cpp(18) : error C2501: 'numtype' : missing storage-class or type specifiers
C:\Users\123\Desktop\practice 5\Cpp1.cpp(18) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

Cpp1.obj - 1 error(s), 0 warning(s)

既然还有不甘心
就还没到放弃的时候~
2015-09-21 10:24
快速回复:程序改错~关于类模板的提问
数据加载中...
 
   



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

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