illegal use of this type as an expression

honglian 2010-10-15 12:12:08
各位好,最近学习VC++6.0,遇到两个问题不知如何解决,请高手们帮忙。
问题一: 代码如下
void CZKAMotionControlDlg::OnButtonCycle()
{
DWORD dwStart, dwEnd;
float time;

for(int i=0; i<10; i++){
dwStart = GetTickCount();
move(m_move_distance);
dwEnd = GetTickCount();
time = (dwEnd-dwStart)*1.0/1000.0; //ms
cout<<"move to start position, use time : "<<time<<endl;
string.Format("Cur. Position : %d", current_position );
GetDlgItem( IDC_STATIC_POSITION_X )->SetWindowText( string );
}
}
编译时出现错误:
error C2143: syntax error : missing ';' before '.'
error C2143: syntax error : missing ';' before '.'
error C2275: 'string' : illegal use of this type as an expression
c:\program files\microsoft visual studio\vc98\include\xstring(612) : see declaration of 'string'



问题二: 代码如下
CZKAMotionControlDlg::CZKAMotionControlDlg(CWnd* pParent /*=NULL*/)
: CDialog(CZKAMotionControlDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CZKAMotionControlDlg)
m_bX = FALSE;
m_bY = FALSE;
m_bU = FALSE;
m_bZ = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
CString string;
zka_get_program_version(i_board_id, version1, version2, version3);

char s[4] = {version1, version2, version3, 0};
string.Format("Program Version : %s", s);
GetDlgItem( IDC_STATIC_PROGRAM_VERSION )->SetWindowText( string ); // **********************
}

运行时出现这个对话框
Debug Assertion Failed!
Program: ...6.0\..\..\ZKAMotionControl.exe
File: winocc.cpp
Line: 76

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
程序运行终止。

问题较急,在线等待,不甚感激!
...全文
308 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
honglian 2010-10-15
  • 打赏
  • 举报
回复
是这两行
string.Format("Cur. Position : %d", current_position );
GetDlgItem( IDC_STATIC_POSITION_X )->SetWindowText( string );
但还是不知道错在哪里了。
另外再问下,怎么给回复的人加分啊?
job82824 2010-10-15
  • 打赏
  • 举报
回复
2275是哪一行?2143行呢?错误还是自己找为佳,增加经验值升级快
honglian 2010-10-15
  • 打赏
  • 举报
回复
第二个问题屏蔽GetDlgItem( IDC_STATIC_PROGRAM_VERSION )->SetWindowText( string ); // **********************
就没有问题了。
honglian 2010-10-15
  • 打赏
  • 举报
回复
明白了,多谢了!
job82824 2010-10-15
  • 打赏
  • 举报
回复
那个叫闪屏,就是启动后最先显示的窗口。和主窗口是分开的,彼此独立的。如果你的软件的确需要较长的初始化时间,可以考虑增加一个闪屏窗口(Loading...),否则就废柴了...
honglian 2010-10-15
  • 打赏
  • 举报
回复
那有没有办法界面一启动就能显示一些信息的?比如程序一运行就能显示当前软件版本号。
job82824 2010-10-15
  • 打赏
  • 举报
回复
第二个问题
GetDlgItem( IDC_STATIC_PROGRAM_VERSION )写在了类的构造函数中了。这时候对话框的控件尚未创建,获得的当然是空指针了。应该改在OnInitDialog()函数中获取子控件指针。
honglian 2010-10-15
  • 打赏
  • 举报
回复
呵呵,一句话提醒了我,太大意了,是string没有定义,多谢了!
第一个问题已解决,但是第二个问题呢?请大侠帮忙!
AlanBruce 2010-10-15
  • 打赏
  • 举报
回复
kankan..
job82824 2010-10-15
  • 打赏
  • 举报
回复
string是什么类型的?

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧