求解。。为什么说我构造函数和析构函数未定义?
c4droid吧
全部回复
仅看楼主
level 5
维系888 楼主
#ifndef SCREEN_H
#define SCREEN_H
#include<string>
#include<SDL2/SDL.h>
class Screen
{
private:
Uint32 flags;
int width, hight,
bp
p;
std::string windowsname;
static int num;
SDL_Surface * screen;
public:
Screen(int w,int h,std::string & setname,Uint32 f);
~Screen();
SDL_Surface * showpoint();
void flip();
};
#endif
#include"screen.h"
int Screen::num=0;
Screen::Screen(int w,int h,std::string & setname,Uint32 f)
{
if (num==1)
throw "Screen can't be created more than one";
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
throw "SDL_INIT wrong";
if ((screen=SDL_SetVideoMode(w,h,32,f))!=0)
throw "screen can't be creen";
width=w;
hight=h;
bpp=32;
flags=f;
SDL_WM_SetCaption(setname.c_str(),NULL);
windowsname=setname;
}
Screen::~Screen()
{
SDL_Quit();
}
SDL_Surface * Screen::showpoint()
{
return screen;
}
void Screen::flip()
{
if ((SDL_Flip(screen))==-1)
throw "flip wrong";
}
#include"screen.h"
#include<string>
#include<iostream>
int main()
{std::string ms="hello";
try
{
Screen sc(640,320,ms,SDL_SWSURFACE);
}
catch (char*m)
{
std::cout<<m;
}
std::cout<<"successfully operated";
return 0;
}
2016年12月06日 22点12分 1
level 11
我就一句话?书仔细看过了没?定义了带参数的构造函数,就必须定义一个默认构造函数,不带参数或者参数都是默认值,我发一个我写的类你对照一下
2016年12月10日 14点12分 5
好~请发给我一个~谢谢~
2016年12月10日 23点12分
好像明白了~一定要有一个不带参数的构造函数是么
2016年12月11日 00点12分
@维系888 不全是,可以有一个全部是默认参数的默认构造参数
2016年12月16日 04点12分
level 11
定义发不了全部,就类声明应该能看出来了
2016年12月10日 14点12分 7
level 5
维系888 楼主
2016年12月11日 00点12分 8
level 5
维系888 楼主
为什么说undefimed一大堆。。所有的SDL函数都这样
2016年12月11日 00点12分 9
你必须加个空格在 <SDL2/...前面,不能多也不能少
2016年12月11日 00点12分
@不知者来此 什么?
2016年12月11日 00点12分
@维系888 不解释
2016年12月11日 00点12分
好吧~
2016年12月11日 00点12分
1