从VS 6到VS 2010的C ++转换 [英] C++ Conversion from VS 6 to VS 2010
问题描述
我正在将项目从Visual Studio 6转换为Visual Studio 2010,并在VS 2010中进行转换.
I am converting a project from Visual Studio 6 to Visual Studio 2010, and in VS 2010. The following line:
m_string.AddTail((CList *)&t.m_string);
给出编译错误:
gives the compile error:
error C2664: 'POSITION CList<type,arg_type>::AddTail(ARG_TYPE)' : cannot convert parameter 1 from '<clist><type,arg_type> *' to 'ATL::CStringT<BaseType,StringTraits> '
with
[
TYPE=CString,
ARG_TYPE=CString &
]
and
[
TYPE=CTickLabel::=::CString,
ARG_TYPE=CTickLabel::=::CString
]
and
[
BaseType=char,
StringTraits=StrTraitMFC<char>
]
任何帮助都将不胜感激!!!!
斯科特
///////////////////////UPDATE///////////////////////////////////
m_string的定义是:
Any help is greatly appreciated!!!!
Scott
///////////////////////UPDATE///////////////////////////////////
The definition of m_string is:
CList <cstring,> m_string;
"t"是传递给例程的参数,其形式为:"const CTickLabel& t''
与:
''t'' is a parameter passed into the routine as: ''const CTickLabel& t''
with:
class CTickLabel : public CObject
{
DECLARE_SERIAL(CTickLabel)
public:
CList <cstring,> m_string;
int m_angle; // angle of ticklabel
如果对问题的结构有任何疑问,请发送电子邮件.
谢谢.
Scott
Please e-mail if any questions about the structure of the problem.
Thank you.
Scott
推荐答案
正如Albert所说,似乎编译器为函数选择了错误的重载.但是,如果要附加完全相同类型的对象,我看不到为什么需要在调用中进行强制转换.您应该能够写:
m_string.AddTail(& t.m_string);
因此,回到VC6,进行转换,并在尝试编译时查看其内容.这可能使您(和我们)对发生的事情有了更好的了解.
另一个问题是什么?
顺便说一下,拥有公共数据成员确实是一个废话.如果让任何老汤姆,迪克或哈里摆弄它们的零头,要保持班级的不变性确实很困难. AND m_string也是一个很糟糕的名字-它是一个糟糕的清单!
我刚刚注意到的另一件事...您没有明确告诉编译器ARG_TYPE是什么.也许指定(例如CList< cstring,cstring&>)可能会有所帮助.
干杯,
灰
As Albert said it looks like the compiler''s choosing the wrong overload for the function. However I can''t see why you need the cast in the call if you''re appending an object of exactly the same type. You should be able to write:
m_string.AddTail( &t.m_string );
So go back to VC6, take the cast out and see what it says when you try and compile it. That might give you (and us) a better idea of what''s going on.
Another question, what''s cstring?
Incidentally having public data members is a really crap idea. It''s really hard to keep your class''s invariants intact if you let any old Tom, Dick or Harry fiddle with their bits. AND m_string is a really bad name as well - it''s a sodding list!
Another thing I''ve just noticed... you''re not explicitly telling the compiler what ARG_TYPE is. Perhaps specifying that (i.e. CList<cstring,cstring & >) might help.
Cheers,
Ash
这篇关于从VS 6到VS 2010的C ++转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!