This topic has been archived. It cannot be replied.
-
工作学习 / 专业技术讨论 / 紧急求助!MFC/C++中如何对MFC或SDK中的类进行重定义?重新定义之后怎么编译出错?是不是在工程文件中需要进行设置?谢谢了!!!For example, I redefined a class CException, which is included in MFC. When I try to compile this project, the error information is this class is redefined. Any one can help me?
-newnewcanada(new);
2006-11-2
{177}
(#3299967@0)
-
没人知?
-newnewcanada(new);
2006-11-2
(#3300280@0)
-
why 重定义?
-oasis(oasis);
2006-11-2
(#3300312@0)
-
这是以前遗留下来的问题,我也不清楚以前的人为什么要这样做?可能是为了增强功能吧。举个例子,你能否自己再申请定义一个CDialog,或者strcpy等等。编译时如何通过?
-newnewcanada(new);
2006-11-2
(#3300397@0)
-
simple solution...#define CException CMyException
class CException
{
...
...
...
};
当然这么做只是替换你当前project里所有的CException而已.
-taop(Bard-Tamer);
2006-11-2
{131}
(#3300352@0)
-
这样做当然也是个办法。问题是我无法对以前公司的project文件进行修改。而且很奇怪,这些重新定义的类或macro在以前的project可以编译,但一移到我自己的project就出错了,不知是何原因?
-newnewcanada(new);
2006-11-2
(#3300386@0)
-
用template specialization...
-interview(intervieweree);
2006-11-2
(#3300403@0)
-
能说的详细点吗?这些类都已经定义好了,肯定没问题的。但我把这些类加到我自己的工程中时,编译报错说类重新定义了。
-newnewcanada(new);
2006-11-2
(#3300425@0)
-
急急急。
-newnewcanada(new);
2006-11-2
(#3300438@0)
-
可能大家还不是很明白我的意思。类已经重新定义好了,而且在以前的project可以用,也可以编译,但移到我的project中就无法编译了。有些宏也是这样子。所以我认为可能是工程文件的设置有问题,但我已经check过任何一项内容,都是一样的,奇怪啊!!!
-newnewcanada(new);
2006-11-2
{91}
(#3300552@0)
-
应该看看深入浅出mfc,有什么mfc的工作介绍给我呀!
-tommy97(随心所欲);
2006-11-3
(#3301114@0)
-
我个人觉得MFC已经停止发展了。我自己有近8年的MFC经验,但是现在做新项目的话会选择ATL和WTL,再也不会选择MFC了。主要原因是MFC的框架侵入性太强,限制了程序的架构。
-dpff(dpff);
2006-11-3
(#3301126@0)
-
我也有7,8年了,还真没用过wtl,那是什么?这个技术都是混饭吃的,年头多也不行,一个考试问如何把HDC转成CDC,我就真不知道.
那有mfc的工作,给俺个信息呀,谢谢大虾和美女.
-tommy97(随心所欲);
2006-11-3
(#3301413@0)
-
检查一下IDE里的include文件搜索路径的设置. 自定义文件路径要优先于MFC的.
-keepbugging(独行的猫);
2006-11-3
(#3301929@0)
-
查了,没可疑之处。
-newnewcanada(new);
2006-11-4
(#3303446@0)
-
是不是有编译开关,可以临时disable/disconnect MFC classes ?
-interview(intervieweree);
2006-11-3
(#3302219@0)
-
我觉得这种可能性很大,但怎么查?我只是查到几个对WARNING进行DISABLE的东东。不知DISABLE重新定义的开关是什么?
-newnewcanada(new);
2006-11-4
(#3303411@0)
-
可能是某些文件中定义的逻辑宏。。。比如 #IFNDEFINE MFC...
-interview(intervieweree);
2006-11-4
(#3303416@0)
-
这个叫conditional compilation.
-interview(intervieweree);
2006-11-4
(#3303421@0)
-
我查了,没看到有什么可疑的东东。都是些WARNING的东西。
-newnewcanada(new);
2006-11-4
(#3303430@0)
-
The only way I know is to put all YOUR classes into a namespace, this would solve the compiling problem.e.g.
namespace MyCompany
{
class CException
{
};
};
and prefix the namespace before the class where it is used:
MyCompany::CException exp;
The problem could be caused that the old project was not using MFC while your project is using MFC. If you are NOT using MFC, disable MFC from project settings, otherwise you have to use namespace.
-dpff(dpff);
2006-11-3
{365}
(#3301037@0)
-
以前的系统是用MFC的,这点我是可以肯定的。我查了一下源代码,就是CException::CException这样子的。我就是搞不懂为什么以前的可以,我COPY过来就不能用了呢?
-newnewcanada(new);
2006-11-3
(#3302111@0)
-
C++ compiler will report error if it sees two class definations have same name in same namespace.If you don't specify a namespace in front the class, the class will be put into the default global namespace. Put your classes into another namespace other than the defualt is the only choice. Don't try to change the include folder or IDE settintgs, it won't work.
-dpff(dpff);
2006-11-3
{267}
(#3302422@0)
-
yeah, you are right. Actually the class CException is derived by CMyClass. The weird thing is this class works in another project, but doesn't work in my project when I copied the whole file into my project.
-newnewcanada(new);
2006-11-4
(#3303067@0)
-
That's because MFC has a class CException and conflicts with yours.
-dpff(dpff);
2006-11-4
(#3303240@0)
-
对啊,我就是搞不懂为何人家的可以通过COMPILE,我的却不行?
-newnewcanada(new);
2006-11-4
(#3303408@0)
-
我来说个方案,如果原来的project很大很复杂,采取我这个方法钱请慎重考虑时间
如果原来的project你可以handle,继续。
你把原来的project抄一个copy,看看是不是可以编译的过。如果不行,自己查问题。如果行,add你自己的文件,编译,应该可以通过。然后审查一边,删除别人的不必要的code.
你看如何?
这叫没有办法的办法。。。
-interview(intervieweree);
2006-11-4
{306}
(#3303307@0)
-
这确实也是个办法,我会试试。原来的PROJECT我全部REBUILD过,没有任何问题。
-newnewcanada(new);
2006-11-4
(#3303407@0)
-
对啊。。。我想,你在精简这个project的过程当中,会明白你自己的为什么不行了。。。很好的学习机会。等你精简完了,自己做个prototype,那上来分享一下,到这一步,别人的知识就成了你的了。。。。
-interview(intervieweree);
2006-11-4
(#3303413@0)
-
呵呵,谢谢了。
-newnewcanada(new);
2006-11-4
(#3303434@0)
-
特别注意,如果由define guid, 你要注意修改,。。。不然惨了。。。。
-interview(intervieweree);
2006-11-4
(#3303459@0)
-
macro is not the solution and should be avoided. If you choose the same class name, you must explicitly prefix them with different namespaces if both are included.
-wangqingshui(忘情水);
2006-11-4
(#3303472@0)
-
The best solution I can see is choose another class name. I don't see the necessity of using the same class name.
-wangqingshui(忘情水);
2006-11-4
(#3303473@0)
-
yes, you are right. but I have no idea. Those classes were included in that old project everywhere. It is impossible to modify them at present.
-newnewcanada(new);
2006-11-5
(#3304492@0)
-
lso it's not a good idea to copy file from one project to another. Copy -and-paste is the easiest way for code reuse but is also the worst way.
-wangqingshui(忘情水);
2006-11-4
(#3303474@0)
-
I am wondering if you are experiencing compiling error or linking error. If it's link error, probably the conflict is not between your class and MFC class but 2 definitions from your project:one is the previous defintion and the other is your copy.
-wangqingshui(忘情水);
2006-11-4
{57}
(#3303476@0)
-
I definitely say it is compile errors.
-newnewcanada(new);
2006-11-5
(#3304487@0)
-
Have you tried to see the precompile result files? Add option -E to the compiler and check the precompiled file to see what 2 definitions and then to decide to use #if defined(...) to control it or else.
-wangqingshui(忘情水);
2006-11-8
(#3309573@0)
-
把报错和号码贴上来
-zjx_cool(zjx);
2006-11-5
(#3304477@0)
-
error C2011: 'CException' : 'class' type redefinition
-newnewcanada(new);
2006-11-5
(#3304488@0)