文号
t33939
阅读
4633
回复
4
收藏
3
多线程同步临界区设置
2011/05/31
IP:福建
在多线程中,我在全局变量里面定义了CCriticalSection   cs;   想让多线程同步,可是一编译就会出现下面的错误提示:
1,error   C2146:   syntax   error   :   missing   '; '   before   identifier   'cs '
2,error   C2501:   'CCriticalSection '   :   missing   storage-class   or   type   specifiers
3,fatal   error   C1004:   unexpected   end   of   file   found

我想加上这个语句应该没有什么问题呀,也不会打错,并且“;”也加了,到底是什么原因呢?百思不得其解,希望各位帮忙。

CCriticalSection CS; 这句到底该放在哪里呢
15年7个月前IP:未同步
297470
1楼
居然可以了!
#include "afxmt.h"      //只不过是把这句放到这些头文件的后面
#include "stdafx.h"
#include "ExMultithreading.h"
#include "ExMultithreadingDoc.h"
#include "ExMultithreadingView.h"

变成
#include "stdafx.h"
#include "ExMultithreading.h"
#include "ExMultithreadingDoc.h"
#include "ExMultithreadingView.h"
#include "afxmt.h"

这不是坑人嘛!
说不出为什么...哪位牛人能解释一下?
引用
评论
15年7个月前IP:未同步
297471
2楼
如果你用的是VC,且工程中使用了“预编译头文件”功能,那么#include "stdafx.h"必须放在第一句
引用
评论
15年7个月前IP:未同步
297490
3楼
CCriticalSection是MFC类,一定要包括MFC的头文件
引用
评论
15年7个月前IP:未同步
297544
4楼
没错是这样,学习了,谢谢所有楼上的
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的