24小时热门版块排行榜    

Znn3bq.jpeg
查看: 780  |  回复: 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的回帖
相关版块跳转 我要订阅楼主 黄小霞 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 085600材料与化工349分求调剂 +8 李木子啊哈哈 2026-04-12 9/450 2026-04-12 22:55 by 李木子啊哈哈
[考研] 290求调剂 +14 柯淮然 2026-04-12 16/800 2026-04-12 19:22 by dan_wang
[考研] 电子信息270求调剂 +18 terminal469 2026-04-07 18/900 2026-04-12 16:23 by ajpv风雷
[考研] 299求调剂 +8 ZVVZ13 2026-04-08 8/400 2026-04-12 00:40 by 蓝云思雨
[考研] 化学308分求调剂 +22 你好明天你好 2026-04-07 24/1200 2026-04-11 11:14 by ChemPharm
[考研] 283求调剂 +22 那个噜子 2026-04-09 22/1100 2026-04-11 10:41 by 逆水乘风
[考研] 调剂 +19 小张ZA 2026-04-10 20/1000 2026-04-10 22:08 by 猪会飞
[考研] 计算机类求调剂,22408-274分 +7 上岸de小虫 2026-04-09 8/400 2026-04-10 19:56 by fxue1114
[考研] 一志愿矿大,材料工程专硕314分,0856可调都可以 +15 无懈可击的巨人 2026-04-09 15/750 2026-04-10 18:10 by hmn_wj
[考研] 一志愿西交机械专硕求调剂 +8 求上岸的小王 2026-04-10 8/400 2026-04-10 15:09 by hemengdong
[考研] 调剂申请086000一志愿西北农林科技大学生物与医药320分-本科齐鲁工业大学 +3 美美女士 2026-04-09 3/150 2026-04-10 10:31 by liuhuiying09
[考研] 考研二轮调剂 +8 故人?? 2026-04-09 8/400 2026-04-10 09:44 by 青梅duoduo
[考研] 本科211 工科085400 280分求调剂 可跨专业 +3 LZH(等待调剂中 2026-04-09 3/150 2026-04-09 21:29 by wutongshun
[考研] 331求调剂 +5 luoxin0706. 2026-04-08 5/250 2026-04-08 22:15 by zhouyuwinner
[考研] 270求调剂 +3 031127 2026-04-06 4/200 2026-04-08 21:00 by 逆水乘风
[考研] 265求调剂 +19 小木虫085600 2026-04-06 21/1050 2026-04-08 10:38 by 逆水乘风
[考研] 304求调剂 +10 素年祭语 2026-04-06 17/850 2026-04-08 09:05 by 蓝云思雨
[考研] 调剂 +4 mcbbc 2026-04-06 5/250 2026-04-07 12:33 by upczlm1989
[考研] 287分求调剂 有专利国奖一志愿哈工大085406 +6 白易辰 2026-04-06 7/350 2026-04-06 22:46 by 875465
[考研] 362求调剂一志愿中国石油大学 +4 我要考大 2026-04-06 6/300 2026-04-06 14:11 by 无际的草原
信息提示
请填处理意见