24小时热门版块排行榜    

查看: 766  |  回复: 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的回帖

黄小霞

铜虫 (小有名气)

引用回帖:
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的回帖
查看全部 5 个回答

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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 接收2026硕士调剂(学硕+专硕) +3 allen-yin 2026-03-23 4/200 2026-03-23 12:27 by allen-yin
[考研] 一志愿070300浙大化学358分,求调剂! +4 酥酥鱼.. 2026-03-21 4/200 2026-03-23 08:12 by Iveryant
[考研] 一志愿东华大学化学070300,求调剂 +7 2117205181 2026-03-21 8/400 2026-03-22 22:55 by chixmc
[考研] 一志愿武理材料工程348求调剂 +5  ̄^ ̄゜汗 2026-03-19 7/350 2026-03-22 19:44 by 公瑾逍遥
[考研] 寻找调剂 +4 倔强芒? 2026-03-21 4/200 2026-03-22 16:14 by 木托莫露露
[考研] 311求调剂 +3 26研0 2026-03-20 3/150 2026-03-22 14:46 by ColorlessPI
[基金申请] 山东省面上项目限额评审 +4 石瑞0426 2026-03-19 4/200 2026-03-22 08:50 by Wei_ren
[考研] 材料工程专硕 348分求调剂 +3 冬辞. 2026-03-17 5/250 2026-03-21 18:47 by 学员8dgXkO
[考研] 一志愿南大,0703化学,分数336,求调剂 +3 收到VS 2026-03-21 3/150 2026-03-21 18:42 by 学员8dgXkO
[考研] 求助 +5 梦里的无言 2026-03-21 6/300 2026-03-21 17:51 by 学员8dgXkO
[考研] 332求调剂 +3 凤凰院丁真 2026-03-20 3/150 2026-03-21 10:27 by luoyongfeng
[考研] 346求调剂[0856] +4 WayneLim327 2026-03-16 7/350 2026-03-21 04:02 by JourneyLucky
[考研] 332求调剂 +4 ydfyh 2026-03-17 4/200 2026-03-21 02:20 by JourneyLucky
[考研] 330求调剂 +4 小材化本科 2026-03-18 4/200 2026-03-20 23:13 by JourneyLucky
[考研] 295材料求调剂,一志愿武汉理工085601专硕 +5 Charlieyq 2026-03-19 5/250 2026-03-20 20:35 by JourneyLucky
[考研] 261求B区调剂,科研经历丰富 +3 牛奶很忙 2026-03-20 4/200 2026-03-20 19:34 by JourneyLucky
[考研] 一志愿南理工085701环境302求调剂院校 +3 葵梓卫队 2026-03-20 3/150 2026-03-20 19:28 by zhukairuo
[考研] 生物学调剂招人!!! +3 山海天岚 2026-03-17 4/200 2026-03-19 21:34 by 怎么释怀
[考研] 材料考研调剂 +3 xwt。 2026-03-19 3/150 2026-03-19 11:22 by w沐阳w
[考研] 材料工程专硕调剂 +5 204818@lcx 2026-03-17 6/300 2026-03-18 22:55 by 204818@lcx
信息提示
请填处理意见