大神来帮忙

dhc_6huoCangLong 2009-07-09 02:54:13
如下三个文件在一个工程里,
但是编译不通过,n多错误,
大部分提示缺少“;”,第一个错误是说SellTickets不是一个类或者结构体
请高手指点
SellTickets.h文件

#ifndef SELL_TICKETS_H
#define SELL_TICKETS_H

#include "afxmt.h"

class SellTickets //卖票类
{
public:
SellTickets(int n);
~SellTickets();
void ShowWindowNum(); //输出窗口号
void ShowTicketsCount(); //输出车票数量
void SellOneTicket(); //卖一张票
private:
CMutex m_mutex;
int num; //窗口号码
int count; //车票数量

};

#endif

SellTickets.cpp文件
#include "SellTickets.h"
#include "stdafx.h"
#include "iostream"

using namespace std;

SellTickets::SellTickets(int n)
{
SellTickets::count = 100; //车票总数
SellTickets::num = n; //窗口号
SellTickets::m_mutex.Lock();//上锁
}
SellTickets::~SellTickets()
{
SellTickets::m_mutex.Unlock();//解锁
}

void SellTickets::ShowWindowNum()
{
cout<<"这是"<<num<<"号窗口"<<endl;
}

void SellTickets::ShowTicketsCount()
{
cout<<"车票总数:"<<count<<endl;
}

void SellTickets::SellOneTicket()
{
if(count>0)
SellTickets::count--;//车票数量减一
else
{
cout<<"车票已经卖完了"<<endl;
cin.get();
cin.get();
}
}

main函数所在文件
#include "SellTickets.h"
#include "stdafx.h"
#include "iostream"

using namespace std;

DWORD WINAPI ThreadProc1(LPVOID lpParameter)
{
cout<<"窗口1卖票"<<endl;
SellTickets t1(1); //循环调用,一直卖票直到卖完
while(1)
{
t1.ShowTicketsCount();
t1.SellOneTicket();
Sleep(500);
}
return 0;
}

DWORD WINAPI ThreadProc2(LPVOID lpParameter)
{
cout<<"窗口2卖票"<<endl;
SellTickets t2(2);
while(1)
{
t2.ShowTicketsCount();
t2.SellOneTicket();
Sleep(500);
}
return 0;
}

void main()
{
//模拟两个窗口同时卖票
HANDLE hThread1 = CreateThread(NULL,NULL,ThreadProc1,NULL,NULL,NULL);
HANDLE hThread2 = CreateThread(NULL,NULL,ThreadProc2,NULL,NULL,NULL);
}
...全文
70 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dhc_6huoCangLong 2009-07-10
  • 打赏
  • 举报
回复
问题已经解决
百度知道
共享dll
哈哈
dhc_6huoCangLong 2009-07-09
  • 打赏
  • 举报
回复
当我将
#include "SellTickets.h"
#include "stdafx.h"
#include "iostream"
变成
#include "stdafx.h"
#include "iostream"
#include "SellTickets.h"
后,
编译SellTickets.cpp,错误从11个减少到1个,如下:

错误 1 fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] c:\program files\microsoft visual studio 8\vc\atlmfc\include\afx.h 24
dhc_6huoCangLong 2009-07-09
  • 打赏
  • 举报
回复
确定 呵呵
[Quote=引用 4 楼 lingyin55 的回复:]
确定这些文件都已经添加进工程


引用 3 楼 dhc_6huoCangLong 的回复:
a ?那怎么回事 为什么在我的vs2005中却39个错误。。。
[/Quote]
lingyin55 2009-07-09
  • 打赏
  • 举报
回复
确定这些文件都已经添加进工程

[Quote=引用 3 楼 dhc_6huoCangLong 的回复:]
a ?那怎么回事 为什么在我的vs2005中却39个错误。。。
[/Quote]
dhc_6huoCangLong 2009-07-09
  • 打赏
  • 举报
回复
a ?那怎么回事 为什么在我的vs2005中却39个错误。。。
大前置 2009-07-09
  • 打赏
  • 举报
回复
vc6.0
编译成Release版

如下:
Compiling...
Cpp2.cpp
SellTickets.cpp
Linking...

Cpp2.exe - 0 error(s), 0 warning(s)


编译通过啊
dhc_6huoCangLong 2009-07-09
  • 打赏
  • 举报
回复
这个程序有很明显的逻辑问题
但是应该能编译通过啊?

64,282

社区成员

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

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