C++编译问题,在线等待!!

MOMO籽 2011-04-04 10:42:25

//momogame.h
namespace Wnd
{
const DWORD LEFT =-1, TOP = -2;
const DWORD RIGHT = -3, DOWN = -4;
const DWORD XCENTRE = -5, YCENTRE = -6;
const DWORD DEFULT = CW_USEDEFAULT;
DWORD CountWndPos( DWORD pos, const GameWindow *wnd, const GameWindow *parentwnd );
}
//load.cpp
DWORD Wnd::CountWndPos( DWORD pos, const GameWindow *wnd, const GameWindow *parentwnd = NULL )
{
if( wnd == NULL)
return pos;
DWORD with = wnd ->GetWith();
DWORD height = wnd ->GetHeight();
if( parent == NULL )
{
parentwith = GetSystemMetrics(SM_CXSCREEN);
parentheight = GetSystemMetrics(SM_CYSCREEN);
}
else
{
DWORD parentwith = parentwnd ->GetWith();
DWORD parentheight = parentwnd ->GetHeight();
}
switch( pos )
{
case XCENTRE:
return ( parentwith - with )/2;
case YCENTRE:
return ( parentheight - height )/2;
case DEFULT:
return DEFULT;
case LEFT:
case TOP:
return 0;
case RIGHT:
return parentwith - with;
case DOWN:
return parentheight - height;
}
return pos;
}

VS2008编译上面代码时出现
1>d:\vc++工作文件夹\my_dx\momogame.h(23) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\vc++工作文件夹\my_dx\momogame.h(23) : error C2143: 语法错误 : 缺少“,”(在“*”的前面)
1>d:\vc++工作文件夹\my_dx\load.cpp(4) : error C2244: “CountWndPos”: 无法将函数定义与现有的声明匹配
1> d:\vc++工作文件夹\my_dx\load.cpp(3) : 参见“CountWndPos”的声明
1>d:\vc++工作文件夹\my_dx\load.cpp(4) : fatal error C1903: 无法从以前的错误中恢复;正在停止编译

其中Wnd声明在momogame.h,CountWndPos实现在load.cpp,看半天看不懂哪里错了,望高手指导!!
...全文
204 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
mstlq 2011-04-04
  • 打赏
  • 举报
回复
namespace Wnd
{
const DWORD LEFT =-1, TOP = -2;
const DWORD RIGHT = -3, DOWN = -4;
const DWORD XCENTRE = -5, YCENTRE = -6;
const DWORD DEFULT = CW_USEDEFAULT;
DWORD CountWndPos( DWORD pos, const GameWindow *wnd, const GameWindow *parentwnd );//编译器看到这里的时候,还真不知道GameWindow是什么
}

类比

int main()
{
a=1;//编译器看到这里的时候,还真不知道a是什么
int a;
}
MOMO籽 2011-04-04
  • 打赏
  • 举报
回复
你仔细看看,声明和定义都有了,它是一个抽象类
mstlq 2011-04-04
  • 打赏
  • 举报
回复

class GameWindow;//这里前向声明 
namespace Wnd
{
const DWORD LEFT =-1, TOP = -2;
const DWORD RIGHT = -3, DOWN = -4;
const DWORD XCENTRE = -5, YCENTRE = -6;
const DWORD DEFULT = CW_USEDEFAULT;
DWORD CountWndPos( DWORD pos, const GameWindow *wnd, const GameWindow *parentwnd );
}
mstlq 2011-04-04
  • 打赏
  • 举报
回复
GameWindow这个类的声明在哪里呢?
MOMO籽 2011-04-04
  • 打赏
  • 举报
回复
最主要是不明白为什么会出现这样的语法错误:
error C2143: 语法错误 : 缺少“,”(在“*”的前面)
MOMO籽 2011-04-04
  • 打赏
  • 举报
回复
唉~~本来我不想把整个文件贴出来的,篇幅太长了,不过你们硬要,我就贴吧
momogame.h

/*-----------------------------------头文件部分------------------------------------*/
#include <windows.h>
#include <ddraw.h>
#include <string.h>
#pragma comment(lib, "ddraw.lib")
#pragma comment(lib, "dxguid.lib")
/*-----------------------------------预处理部分-----------------------------------*/
#define DDRAW_INIT_STRUCT(ddstruct) { memset(&ddstruct, 0, sizeof(ddstruct)); ddstruct.dwSize = sizeof(ddstruct); }
//位图结构
typedef struct tagBITMAP_FILE_TAG
{
BITMAPFILEHEADER fileheader;
BITMAPINFOHEADER infoheader;
LPBYTE buffer;
}BITMAPSTRUCT, * LPBITMAPSTRUCT ;
//游戏窗口常量
namespace Wnd
{
const DWORD LEFT =-1, TOP = -2;
const DWORD RIGHT = -3, DOWN = -4;
const DWORD XCENTRE = -5, YCENTRE = -6;
const DWORD DEFULT = CW_USEDEFAULT;
DWORD CountWndPos( DWORD pos, const GameWindow *wnd, const GameWindow *parentwnd );
}
/*---------------------------------类型定义部分----------------------------------*/
//DDraw对象类
class DriectDraw
{
public:
DriectDraw();
~DriectDraw();
const LPDIRECTDRAW7 GetLPDriectDraw() const{ return lpdd; }
private:
LPDIRECTDRAW7 lpdd;
};
//DDrawSuface页面类
class DDrawSuface
{
public:
DWORD with;
DWORD height;
DWORD bit;
DDrawSuface();
virtual ~DDrawSuface() = 0;
virtual bool Create( const DriectDraw& );
const LPDIRECTDRAWSURFACE7 GetLPDDrawSuface() const{ return lpddsuface; }
void GetInfo();
protected:
LPDIRECTDRAW7 lpdd;
bool flag;
DDSURFACEDESC2 ddsd;
LPDIRECTDRAWSURFACE7 lpddsuface;
};
//MainSuface主页面类
class MainSuface :public DDrawSuface
{
public:
MainSuface();
~MainSuface(){}
};
//BackSuface从页面类
class BackSuface :public DDrawSuface
{
public:
BackSuface( DWORD, DWORD );
~BackSuface(){}
};
//DDrawClipper剪裁器类
class DDrawClipper
{
public:
DDrawClipper();
virtual ~DDrawClipper() = 0;
virtual bool Create( const DriectDraw& ddraw );
const LPDIRECTDRAWCLIPPER GetLPClipper() const{ return lpddclipper; }
protected:
LPDIRECTDRAW7 lpdd;
bool flag;
LPDIRECTDRAWCLIPPER lpddclipper;
};
//GameWindow窗口类
class GameWindow
{
public:
GameWindow::GameWindow( const WNDCLASSEX &wc, LPCSTR title = TEXT("MOMO游戏"),
DWORD Xpos = CW_USEDEFAULT, DWORD Ypos = CW_USEDEFAULT,
DWORD with = CW_USEDEFAULT, DWORD height = CW_USEDEFAULT,
DWORD style = WS_OVERLAPPEDWINDOW, DWORD EXstyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
virtual ~GameWindow() = 0{};
const HDC GetDC() const{ return ::GetDC( hwnd ); }
const HINSTANCE GetInstance() const{ return hinstance; }
const DWORD GetWith() const{ return with; }
const DWORD GetHeight() const { return height; }
const WNDCLASSEX GetWndClass() const { return wc; }
const HWND GetParent() const{ return hparent; }
virtual bool Create();
void Show( int );
bool Destroy(){ return (bool)DestroyWindow( hwnd ); }
protected:
LPCSTR title;
DWORD EXstyle;
DWORD style;
DWORD Xpos;
DWORD Ypos;
DWORD with;
DWORD height;
WNDCLASSEX wc;
HWND hparent;
HWND hwnd;
HINSTANCE hinstance;
};
//MainWindow主窗口类
class MainWindow :public GameWindow
{
public:
MainWindow( WNDCLASSEX, LPCSTR, DWORD, DWORD, DWORD, DWORD );
MainWindow( WNDCLASSEX, RECT, DWORD );
virtual ~MainWindow();
const DWORD GetScreenWith() const{ return screenwith; }
const DWORD GetScreenHeight() const{ return screenheight; }
const DWORD GetColorBit() const{ return bit; }
bool SetDisplayMode( DWORD, DWORD, DWORD );
virtual bool Create();
private:
static bool flag;
bool fullscreenflag;
DWORD screenwith;
DWORD screenheight;
DWORD bit;
};

load.cpp

#include "MOMOgame.h"
//函数实现部分
DWORD Wnd::CountWndPos( DWORD pos, const GameWindow *wnd, const GameWindow *parentwnd = NULL )
{
if( wnd == NULL)
return pos;
DWORD with = wnd ->GetWith();
DWORD height = wnd ->GetHeight();
if( parent == NULL )
{
parentwith = GetSystemMetrics(SM_CXSCREEN);
parentheight = GetSystemMetrics(SM_CYSCREEN);
}
else
{
DWORD parentwith = parentwnd ->GetWith();
DWORD parentheight = parentwnd ->GetHeight();
}
switch( pos )
{
case XCENTRE:
return ( parentwith - with )/2;
case YCENTRE:
return ( parentheight - height )/2;
case DEFULT:
return DEFULT;
case LEFT:
case TOP:
return 0;
case RIGHT:
return parentwith - with;
case DOWN:
return parentheight - height;
}
return pos;
}
//类实现部分
//DriectDraw类
DriectDraw::DriectDraw()
{
if ( FAILED(DirectDrawCreateEx( NULL, (void**)&lpdd, IID_IDirectDraw7, NULL ) ) )// 创建DirectCraw对象
{
MessageBox ( NULL, TEXT("创建DirectCraw对象错误!"),
TEXT("错误!"), MB_ICONERROR);
lpdd = NULL;
}
}
DriectDraw::~DriectDraw()
{
if( lpdd != NULL )
{
lpdd ->Release();
lpdd = NULL;
}
}
//DDrawSuface类
DDrawSuface::DDrawSuface()
{
DDRAW_INIT_STRUCT( ddsd );
lpddsuface = NULL;
flag = false;
}
DDrawSuface::~DDrawSuface()
{
if( !lpddsuface )
lpddsuface ->Release();
lpddsuface = NULL;
}
bool DDrawSuface::Create( const DriectDraw& ddraw )
{
lpdd = ddraw.GetLPDriectDraw();
if( flag )
{
MessageBox ( NULL, TEXT("已创建页面!"),
TEXT("错误!"), MB_ICONERROR);
return false;
}
if( FAILED(lpdd ->CreateSurface( &ddsd, &lpddsuface, NULL ) ) )
{
MessageBox ( NULL, TEXT("创建页面错误!"),
TEXT("错误!"), MB_ICONERROR);
lpddsuface = NULL;
return false;
}

flag = true;
return true;
}
//MainSufce类
MainSuface::MainSuface()
{
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; // 指定要创建的是主页面
}
//BackSuface类
BackSuface::BackSuface( DWORD w = 800, DWORD h = 600 )
{
with = w;
height = h;
lpdd = NULL;
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ;
ddsd.dwWidth = with;
ddsd.dwHeight = height;
ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN ; // 指定要创建的是从页面
}
//DDrawClipper类
DDrawClipper::DDrawClipper()
{
lpddclipper = NULL;
}
DDrawClipper::~DDrawClipper()
{
if( !lpddclipper )
lpddclipper ->Release();
lpddclipper = NULL;
}
bool DDrawClipper::Create( const DriectDraw& ddraw )
{
lpdd = ddraw.GetLPDriectDraw();
if( flag )
{
MessageBox ( NULL, TEXT("已创建剪裁器!"),
TEXT("错误!"), MB_ICONERROR);
return false;
}
if( FAILED( lpdd ->CreateClipper( 0, &lpddclipper, NULL ) ) )
{
MessageBox ( NULL, TEXT("创建剪裁器错误!"),
TEXT("错误!"), MB_ICONERROR);
lpddclipper = NULL;
return false;
}

flag = true;
return true;
}
//GameWindow类
GameWindow::GameWindow( const WNDCLASSEX &wc, LPCSTR title = TEXT("MOMO游戏"),
DWORD Xpos = CW_USEDEFAULT, DWORD Ypos = CW_USEDEFAULT,
DWORD with = CW_USEDEFAULT, DWORD height = CW_USEDEFAULT,
DWORD style = WS_OVERLAPPEDWINDOW, DWORD EXstyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE)
{
this ->title = title;
this ->EXstyle = EXstyle;
this ->style = style;
this ->Xpos = Xpos;
this ->Ypos = Ypos;
if( with == 0 )
this ->with = 1;
else
this ->with = 1;
if( height == 0 )
this ->height = 1;
else
this ->height = winheight;
this ->wc = wc;
hparent = NULL;
hwnd = NULL;
hinstance = wc.hInstance;
if (!RegisterClass (&wc))
{
MessageBox ( hwnd, TEXT ("错误!不能注册窗口!"),
TEXT ("错误!"), MB_ICONERROR);
}
}
bool GameWindow::Create()
{
if(hwnd = CreateWindow( wc.lpszClassName , // 类别名称
title, // 标题名称
style, // 窗口风格
Xpos, // 初始化起点X坐标
Ypos, // 初始化起点Y坐标
with, // 窗口宽度
height, // 窗口高度
hparent, // 父视窗句柄
NULL, // 菜单栏句柄
hinstance, // 执行实体句柄
NULL) ) // 建立参数指针
return true;
return false;
}
void GameWindow::Show( int iShowWay )
{
ShowWindow( hwnd, iShowWay ); // 显示并更新窗口
UpdateWindow( hwnd ); // 更新窗口
}
//MainWindow游戏主窗口类
MainWindow::MainWindow()
{
title = "MOMO游戏";
}
MainWindow::MainWindow( const WNDCLASSEX &wc, LPCSTR title,
DWORD Xpos = Wnd::XCENTRE, DWORD Ypos = Wnd::YCENTRE, DWORD with = 800, DWORD height = 600 )
:GameWindow( wc, title, Xpos, Ypos, with, height )
{
this ->Xpos = Wnd::CountWndPos( Xpos, this );
this ->Ypos = Wnd::CountWndPos( Ypos, this );
fullscreenflag = false;
screenwith = GetSystemMetrics(SM_CXSCREEN);
screenheight = GetSystemMetrics(SM_CYSCREEN);
bit = GetDeviceCaps( ::GetDC( NULL ), BITSPIXEL );
}
bool MainWindow::flag = false;
無_1024 2011-04-04
  • 打赏
  • 举报
回复
momogame.h有问题的 看注释啊
pengzhixi 2011-04-04
  • 打赏
  • 举报
回复
在.h里面#include <windef.h>
mstlq 2011-04-04
  • 打赏
  • 举报
回复
momogame.h完整贴出来吧……
编译说momogame.h第23行有错误……

楼主贴的不足23行……
搞错文件了吧?

preciousboy 2011-04-04
  • 打赏
  • 举报
回复
mark.我测试了下,也是存在问题,
MOMO籽 2011-04-04
  • 打赏
  • 举报
回复
总算解决了,不过这是不是说我要把所有类得声明都要放在模块的前面呢?
class one;
class two;
.......
namespace one;
namespace two;
....
那样总觉得很别扭
ifengshow 2011-04-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mstlq 的回复:]
momogame.h完整贴出来吧……
编译说momogame.h第23行有错误……

楼主贴的不足23行……
搞错文件了吧?
[/Quote]细心的人呀

64,281

社区成员

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

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