24小时热门版块排行榜    

查看: 768  |  回复: 4

黄小霞

铜虫 (小有名气)

[求助] 为何编不过?哪里错了?

#include
template demol;
template
class CSampleTemplate
{
        private:
                T t1;
                T2 t2;
        public:
                CSampleTemplace(T arg1, T2 arg2)
                {
                        t1=arg1+num;
                        t2=arg2+num;
                }
                void Write()
                {
                        std::cout<<"t1:"<                 }
                ~ CSampleTemmplate(void){}
};
int main(int argc, char* argv[])
{
        CSampleTemplate temp(1,2);
        temp.Write();
        return 0;
}
编辑错误为:ug--------------------
Compiling...
11.cpp
E:\1\11.cpp(2) : error C2991: redefinition of template parameter '__formal'
        E:\1\11.cpp(2) : see declaration of '__formal'
E:\1\11.cpp(2) : error C2059: syntax error : 'constant'
E:\1\11.cpp(2) : error C2501: 'demol' : missing storage-class or type specifiers
E:\1\11.cpp(14) : warning C4183: 'CSampleTemplace': member function definition looks like a ctor, but name does not match enclosing class
        E:\1\11.cpp(20) : see reference to class template instantiation 'CSampleTemplate' being compiled
E:\1\11.cpp(19) : error C2523: 'CSampleTemplate::~CSampleTemmplate' : destructor tag mismatch
        E:\1\11.cpp(20) : see reference to class template instantiation 'CSampleTemplate' being compiled
E:\1\11.cpp(11) : warning C4183: 'CSampleTemplace': member function definition looks like a ctor, but name does not match enclosing class
        E:\1\11.cpp(23) : see reference to class template instantiation 'CSampleTemplate' being compiled
E:\1\11.cpp(19) : error C2523: 'CSampleTemplate::~CSampleTemmplate' : destructor tag mismatch
        E:\1\11.cpp(23) : see reference to class template instantiation 'CSampleTemplate' being compiled
E:\1\11.cpp(23) : error C2661: 'CSampleTemplate::CSampleTemplate' : no overloaded function takes 2 parameters
Error executing cl.exe.

11.obj - 6 error(s), 2 warning(s)
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

caoyjian

金虫 (小有名气)

【答案】应助回帖

感谢参与,应助指数 +1
可以问一下那个demol是干什么的么。。
诚意、正心、修身齐家治国平天下
2楼2012-06-20 11:15:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

caoyjian

金虫 (小有名气)

【答案】应助回帖

好吧 。。把你的程序运行了一遍
最主要的问题呢。。是你的构造函数打成了templace...而应该是template如果我没看错的话,这么久才看出来对不住。。
其次我的运行环境是vs2010,所以改成了iostream,屏蔽了demol和endl还有析构函数。。很久没用模板了,希望对你有帮助。。
诚意、正心、修身齐家治国平天下
3楼2012-06-20 11:43:58
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
4楼2012-06-20 12:16:21
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

黄小霞

铜虫 (小有名气)

引用回帖:
3楼: Originally posted by caoyjian at 2012-06-20 11:43:58
好吧 。。把你的程序运行了一遍
最主要的问题呢。。是你的构造函数打成了templace...而应该是template如果我没看错的话,这么久才看出来对不住。。
其次我的运行环境是vs2010,所以改成了iostream,屏蔽了demol和 ...

谢谢!你好仔细哦!
5楼2012-06-21 08:51:19
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 黄小霞 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 招08考数学 +6 laoshidan 2026-03-20 14/700 2026-03-23 14:37 by 15614359529
[考研] 求调剂材料学硕080500,总分289分 5+3 @taotao 2026-03-19 21/1050 2026-03-23 10:17 by 冠c哥
[考研] 一志愿中南大学化学学硕0703总分337求调剂 +4 niko- 2026-03-22 4/200 2026-03-23 07:56 by Iveryant
[考研] 一志愿北京化工大学 070300 学硕 336分 求调剂 +5 vv迷 2026-03-22 5/250 2026-03-23 07:36 by Iveryant
[考研] 352求调剂 +3 大米饭! 2026-03-22 3/150 2026-03-22 23:28 by king123!
[考研] 275求调剂 +6 shansx 2026-03-22 8/400 2026-03-22 15:27 by barlinike
[考研] 269专硕求调剂 +6 金恩贝 2026-03-21 6/300 2026-03-22 14:31 by ColorlessPI
[考研] 一志愿北京化工大学070300 学硕336求调剂 +5 vv迷 2026-03-21 8/400 2026-03-22 14:20 by ColorlessPI
[考研] 285求调剂 +6 ytter 2026-03-22 6/300 2026-03-22 12:09 by 星空星月
[考研] 299求调剂 +4 某某某某位 2026-03-21 4/200 2026-03-21 16:30 by barlinike
[考研] 材料与化工(0856)304求 B区 调剂 +3 邱gl 2026-03-21 3/150 2026-03-21 13:47 by lature00
[考研] 303求调剂 +5 睿08 2026-03-17 7/350 2026-03-21 03:11 by JourneyLucky
[考研] 二本跨考郑大材料306英一数二 +3 z1z2z3879 2026-03-17 3/150 2026-03-21 02:29 by JourneyLucky
[考研] 考研调剂求学校推荐 +3 伯乐29 2026-03-18 5/250 2026-03-20 22:59 by JourneyLucky
[考研] 0856调剂,是学校就去 +8 sllhht 2026-03-19 9/450 2026-03-20 14:25 by 无懈可击111
[考研] 298-一志愿中国农业大学-求调剂 +9 手机用户 2026-03-17 9/450 2026-03-20 14:24 by 无懈可击111
[考研] 一志愿中国海洋大学,生物学,301分,求调剂 +5 1孙悟空 2026-03-17 6/300 2026-03-19 23:46 by zcl123
[考研] 320求调剂0856 +3 不想起名字112 2026-03-19 3/150 2026-03-19 22:53 by 学员8dgXkO
[考研] 材料考研调剂 +3 xwt。 2026-03-19 3/150 2026-03-19 11:22 by w沐阳w
[论文投稿] 有没有大佬发小论文能带我个二作 +3 增锐漏人 2026-03-17 4/200 2026-03-17 09:26 by xs74101122
信息提示
请填处理意见