当前位置:编程学习 > C#/ASP.NET >>

编译时出现的错误:cannot convert from 'const char [1]' to 'const CComboBox'

写了一个小的程序,功能类似于小型教师信息管理系统。编译时出现的错误:
1>f:\Demos\student\studentdlg.cpp(94) : error C2664: 'CComboBox::CComboBox(const CComboBox &)' : cannot convert parameter 1 from 'const char [1]' to 'const CComboBox &'
1>        Reason: cannot convert from 'const char [1]' to 'const CComboBox'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous
1>f:\Demos\student\studentdlg.cpp(94) : error C2664: 'CComboBox::CComboBox(const CComboBox &)' : cannot convert parameter 1 from 'const char [1]' to 'const CComboBox &'
1>        Reason: cannot convert from 'const char [1]' to 'const CComboBox'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous
1>f:\Demos\student\studentdlg.cpp(94) : error C2664: 'CComboBox::CComboBox(const CComboBox &)' : cannot convert parameter 1 from 'const char [1]' to 'const CComboBox &'
1>        Reason: cannot convert from 'const char [1]' to 'const CComboBox'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous

    我的程序里用了三个ComboBox 控件控件,分别对应的是导师类别、最后学位和最后学历,相关声明如下:

public:
CComboBox m_MentorSort;
public:
CString m_strMentorSort;
public:
CComboBox m_LastXueli;
public:
CString m_strLastXueli;
public:
CComboBox m_LastXuewei;
public:
CString m_strLastXuewei;


        DDX_Control(pDX, IDC_COMBO_MENTORSORT, m_MentorSort);
DDX_CBString(pDX, IDC_COMBO_MENTORSORT, m_strMentorSort);
DDX_Control(pDX, IDC_COMBO_LASTXUELI, m_LastXueli);
DDX_CBString(pDX, IDC_COMBO_LASTXUELI, m_strLastXueli);
DDX_Control(pDX, IDC_COMBO_LASTXUEWEI, m_LastXuewei);
DDX_CBString(pDX, IDC_COMBO_LASTXUEWEI, m_strLastXuewei);

因为代码很多,没法全部贴上来。有个疑惑是不是我的声明哪里出现问题了?还是哪里的问题导致的这样错误,希望大家能够帮助解决一下,明天就要上交了,很是着急 --------------------编程问答-------------------- 错误好象不在你给的代码里,这段代码只是定义6个CComboBox 变量,和你的错误没关系.
错误提示的是类型不匹配,你把出错的那句找错来. --------------------编程问答-------------------- CComboBox换为ComboBox
应该是你在查找控件强制转换的时候出的问题 --------------------编程问答-------------------- 94行贴出来嘛 --------------------编程问答-------------------- 实在太疏忽了,忘记把出错行贴出来了:
92 , m_strLastXuewei(_T(""))
93 , m_IDNum(_T(""))
94{
95 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
96}
我最近才开始学习用vc.net,因此希望大家能指导一下。 --------------------编程问答-------------------- 能说的详细一些么?具体怎么转换?我是最近才学习vc.net的。 --------------------编程问答-------------------- 能不能再贴的多一点? --------------------编程问答-------------------- 将控件变量类型改为value类型嘛,我想就可以了。
方法就是:1,将上面的public: 
CComboBox m_MentorSort; 
public: 
CString m_strMentorSort; 
public: 
CComboBox m_LastXueli; 
public: 
CString m_strLastXueli; 
public: 
CComboBox m_LastXuewei; 
public: 
CString m_strLastXuewei; 
中的ccombobos改为STring 就行了,


2,另外添加控件变量,为value型的。
--------------------编程问答-------------------- 我说的是两种方法哈,不是两步 --------------------编程问答--------------------
引用 7 楼 wenwu20082008 的回复:
将控件变量类型改为value类型嘛,我想就可以了。
方法就是:1,将上面的public:
CComboBox m_MentorSort;
public:
CString m_strMentorSort;
public:
CComboBox m_LastXueli;
public:
CString m_strLastXueli;
public:
CComboBox m_LastXuewei;
public:
CString m_strLastXuewei;
中的ccombobos改为STring 就行了,


2,另外添加控件变量,为value型的。


CComboBox m_MentorSort;
public:
CString m_strMentorSort;
这里的两个变量分别是对应combobox的控件变量和value型的变量呀 --------------------编程问答-------------------- m_IDNum

这个是什么变量?

谢谢?
--------------------编程问答-------------------- 那有可能是你赋值的时候付错了,把cstring型的赋给combobox型的了 --------------------编程问答-------------------- 刪除控件的相連的對象/變量,改用嚮導來生成控件的對象及value變量
补充:.NET技术 ,  VC.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,