24小时热门版块排行榜    

Znn3bq.jpeg
查看: 779  |  回复: 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

金虫 (小有名气)

【答案】应助回帖

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

caoyjian

金虫 (小有名气)

【答案】应助回帖

感谢参与,应助指数 +1
可以问一下那个demol是干什么的么。。
诚意、正心、修身齐家治国平天下
2楼2012-06-20 11:15:08
已阅   回复此楼   关注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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 279求调剂 +9 张番茄不炒蛋 2026-04-11 9/450 2026-04-12 22:22 by paopaotu326
[考研] 复试调剂 +14 积极向上; 2026-04-10 16/800 2026-04-12 20:02 by gruyclewee
[考研] 366求调剂 +8 不知名的小卅 2026-04-11 8/400 2026-04-12 19:49 by zhouxiaoyu
[考研] 药学305求调剂 +8 玛卡巴卡boom 2026-04-10 8/400 2026-04-12 00:07 by zhouwenxian
[考研] 0859,337求调剂 +4 研s. 2026-04-10 4/200 2026-04-11 11:34 by caotw2020
[考研] 化学308分求调剂 +22 你好明天你好 2026-04-07 24/1200 2026-04-11 11:14 by ChemPharm
[考研] 298求调剂 +5 残荷新柳 2026-04-07 5/250 2026-04-11 11:02 by 紫曦紫棋
[考研] 化工求调剂! +35 RichLi_ 2026-04-06 35/1750 2026-04-11 11:02 by zhq0425
[考研] 085410-273求调剂 +6 X1999 2026-04-10 6/300 2026-04-11 10:32 by Delta2012
[考研] 337求调剂 +4 研s. 2026-04-10 4/200 2026-04-11 08:57 by zhq0425
[考研] 302分求调剂 +9 凡语祈愿 2026-04-08 10/500 2026-04-10 23:26 by 314126402
[考研] 一志愿矿大,材料工程专硕314分,0856可调都可以 +15 无懈可击的巨人 2026-04-09 15/750 2026-04-10 18:10 by hmn_wj
[考研] 085404 298分求调剂 +10 呼啦呼啦呼呼呼 2026-04-10 11/550 2026-04-10 16:44 by wangy0907
[考研] 本科西工大 0856 324求调剂 +10 wysyjs25 2026-04-09 11/550 2026-04-10 08:37 by 5268321
[考研] 材料专硕调剂 +16 哈哈哈吼吼吼哈 2026-04-07 17/850 2026-04-09 21:16 by wutongshun
[考研] 一志愿武理车辆 281 求调剂 +5 上岸研究生. 2026-04-07 5/250 2026-04-09 15:56 by only周
[考研] 311求调剂 +6 surte 2026-04-08 13/650 2026-04-09 14:00 by surte
[考研] 11408 325分 +3 jgtxuxgkx 2026-04-07 3/150 2026-04-07 23:10 by lbsjt
[考研] 22408 318分求调剂 +4 勤奋的小笼包 2026-04-06 6/300 2026-04-07 15:05 by 纸鹤555
[考研] 生物学学硕求调剂:351分一志愿南京师范大学生物学专业 +6 …~、王…~ 2026-04-06 7/350 2026-04-06 18:54 by macy2011
信息提示
请填处理意见