【发布时间】:2020-02-27 23:38:41
【问题描述】:
“cludes.h”是一个头文件,我把我所有的头文件和命名空间都放进去。
hit_box.h
#include "cludes.h"
class hit_box{
friend class player;
private:
/*class members*/
public:
// without this I get "no default constructor" error.
hit_box();
//I think having two constructors will create problems but that's a problem on top of my current problem
hit_box(char typ, int t, int x, int y, float Px, float Py,int pw, float spotx, float spoty);
}
player.h
#pragma once
#include "cludes.h"
class player {
public:
enum states { falling, hurt, landed, jumping };
player(float a, float b, int f, sf::Texture t, sf::Texture t2, hit_box pnch);
private:
//other class members
hit_box punch;
}
player.cpp
#include "player.h"
#include "cludes.h"
player::player(float a, float b, int f, sf::Texture t, sf::Texture t2, hit_box pnch){
/*other class members*/
hit_box punch = pnch;
}
我希望hit_box 成为我可以在播放器类函数中调用的成员。
这些是我收到的错误消息
Error C2061 syntax error: identifier 'hit_box' Error C3646 'punch': unknown override specifier Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
我尝试通过
继承hit_box类
player.h
#include "cludes.h"
class player {
hit_box punch;
public:
player(float a, float b, int f, sf::Texture t, sf::Texture t2);
}
player.cpp
#include "player.h"
#include "cludes.h"
player::player(float a, float b, int f, sf::Texture t, sf::Texture t2) : punch('!', 10, 30, 64, -10, -10, 20, 4.44, 4.44){
//other class members
}
这种方式没有hit_box 默认构造函数,只有非默认构造函数。
不管我还是得到
Error C3646 'punch': unknown override specifier Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
如果这是重要信息,我正在使用 sfml。
【问题讨论】:
-
这是您要编译的实际代码吗?至少,每个类定义后都缺少分号。
标签: c++ visual-c++ sfml