How to declare an object of a class within static class C++? Errors
up vote
-2
down vote
favorite
I have a static class called Map and usual class called Box and I want the map class to manage all the boxes.
Ex:
map.hpp
#pragma once
#include "pch.h"
#include "box.hpp"
using namespace sf;
extern RenderWindow root;
extern Event event;
class Map
{
public:
static int size;
static int x;
static int y;
static Box box[10][10];
static void init();
static void draw();
static bool checkBox(int x, int y);
private:
Map() {}
};
box.hpp
#pragma once
#include "pch.h"
using namespace sf;
extern RenderWindow root;
extern Event event;
class Box
{
public:
std::string type;
int x;
int y;
bool solid;
Sprite sprite;
Texture texture;
void create(std::string itype, int ix, int iy);
void draw();
};
I can declare the box array anywhere in the code except some static classes I created. And I can declare Sprites or Time objects in the map class. Can anyone explain to me why it happens?
1>d:projectsfml_gamemap.hpp(13): error C3646: 'box': unknown override specifier
1>d:projectsfml_gamemap.hpp(13): error C2143: syntax error: missing ',' before '['
1>d:projectsfml_gamemap.hpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:projectsfml_gamemap.hpp(15): error C2143: syntax error: missing ')' before ';'
1>d:projectsfml_gamemap.hpp(15): error C2059: syntax error: ')'
1>d:projectsfml_gamemap.hpp(16): error C2143: syntax error: missing ')' before ';'
1>d:projectsfml_gamemap.hpp(16): error C2059: syntax error: ')'
c++ class static objective-c++
New contributor
|
show 12 more comments
up vote
-2
down vote
favorite
I have a static class called Map and usual class called Box and I want the map class to manage all the boxes.
Ex:
map.hpp
#pragma once
#include "pch.h"
#include "box.hpp"
using namespace sf;
extern RenderWindow root;
extern Event event;
class Map
{
public:
static int size;
static int x;
static int y;
static Box box[10][10];
static void init();
static void draw();
static bool checkBox(int x, int y);
private:
Map() {}
};
box.hpp
#pragma once
#include "pch.h"
using namespace sf;
extern RenderWindow root;
extern Event event;
class Box
{
public:
std::string type;
int x;
int y;
bool solid;
Sprite sprite;
Texture texture;
void create(std::string itype, int ix, int iy);
void draw();
};
I can declare the box array anywhere in the code except some static classes I created. And I can declare Sprites or Time objects in the map class. Can anyone explain to me why it happens?
1>d:projectsfml_gamemap.hpp(13): error C3646: 'box': unknown override specifier
1>d:projectsfml_gamemap.hpp(13): error C2143: syntax error: missing ',' before '['
1>d:projectsfml_gamemap.hpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:projectsfml_gamemap.hpp(15): error C2143: syntax error: missing ')' before ';'
1>d:projectsfml_gamemap.hpp(15): error C2059: syntax error: ')'
1>d:projectsfml_gamemap.hpp(16): error C2143: syntax error: missing ')' before ';'
1>d:projectsfml_gamemap.hpp(16): error C2059: syntax error: ')'
c++ class static objective-c++
New contributor
1
To start with, put a semicolon (;
) after class declarations.
– πάντα ῥεῖ
Nov 10 at 14:01
2
Possibly the definition ofBox
is not in scope. Did you #include the proper file?
– aschepler
Nov 10 at 14:03
1
Indeed, sounds like a missing include.
– Matthieu Brucher
Nov 10 at 14:14
I'd be interested to see the code corresponding to the error messages, and especially theoverride
on the box...
– Christophe
Nov 10 at 14:26
Most likely caused by a missing include file or circular includes.Box
is not declared as a type at the point you're getting the error.
– 1201ProgramAlarm
Nov 10 at 14:32
|
show 12 more comments
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I have a static class called Map and usual class called Box and I want the map class to manage all the boxes.
Ex:
map.hpp
#pragma once
#include "pch.h"
#include "box.hpp"
using namespace sf;
extern RenderWindow root;
extern Event event;
class Map
{
public:
static int size;
static int x;
static int y;
static Box box[10][10];
static void init();
static void draw();
static bool checkBox(int x, int y);
private:
Map() {}
};
box.hpp
#pragma once
#include "pch.h"
using namespace sf;
extern RenderWindow root;
extern Event event;
class Box
{
public:
std::string type;
int x;
int y;
bool solid;
Sprite sprite;
Texture texture;
void create(std::string itype, int ix, int iy);
void draw();
};
I can declare the box array anywhere in the code except some static classes I created. And I can declare Sprites or Time objects in the map class. Can anyone explain to me why it happens?
1>d:projectsfml_gamemap.hpp(13): error C3646: 'box': unknown override specifier
1>d:projectsfml_gamemap.hpp(13): error C2143: syntax error: missing ',' before '['
1>d:projectsfml_gamemap.hpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:projectsfml_gamemap.hpp(15): error C2143: syntax error: missing ')' before ';'
1>d:projectsfml_gamemap.hpp(15): error C2059: syntax error: ')'
1>d:projectsfml_gamemap.hpp(16): error C2143: syntax error: missing ')' before ';'
1>d:projectsfml_gamemap.hpp(16): error C2059: syntax error: ')'
c++ class static objective-c++
New contributor
I have a static class called Map and usual class called Box and I want the map class to manage all the boxes.
Ex:
map.hpp
#pragma once
#include "pch.h"
#include "box.hpp"
using namespace sf;
extern RenderWindow root;
extern Event event;
class Map
{
public:
static int size;
static int x;
static int y;
static Box box[10][10];
static void init();
static void draw();
static bool checkBox(int x, int y);
private:
Map() {}
};
box.hpp
#pragma once
#include "pch.h"
using namespace sf;
extern RenderWindow root;
extern Event event;
class Box
{
public:
std::string type;
int x;
int y;
bool solid;
Sprite sprite;
Texture texture;
void create(std::string itype, int ix, int iy);
void draw();
};
I can declare the box array anywhere in the code except some static classes I created. And I can declare Sprites or Time objects in the map class. Can anyone explain to me why it happens?
1>d:projectsfml_gamemap.hpp(13): error C3646: 'box': unknown override specifier
1>d:projectsfml_gamemap.hpp(13): error C2143: syntax error: missing ',' before '['
1>d:projectsfml_gamemap.hpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:projectsfml_gamemap.hpp(15): error C2143: syntax error: missing ')' before ';'
1>d:projectsfml_gamemap.hpp(15): error C2059: syntax error: ')'
1>d:projectsfml_gamemap.hpp(16): error C2143: syntax error: missing ')' before ';'
1>d:projectsfml_gamemap.hpp(16): error C2059: syntax error: ')'
c++ class static objective-c++
c++ class static objective-c++
New contributor
New contributor
edited Nov 10 at 14:51
New contributor
asked Nov 10 at 13:57
Blukennel
11
11
New contributor
New contributor
1
To start with, put a semicolon (;
) after class declarations.
– πάντα ῥεῖ
Nov 10 at 14:01
2
Possibly the definition ofBox
is not in scope. Did you #include the proper file?
– aschepler
Nov 10 at 14:03
1
Indeed, sounds like a missing include.
– Matthieu Brucher
Nov 10 at 14:14
I'd be interested to see the code corresponding to the error messages, and especially theoverride
on the box...
– Christophe
Nov 10 at 14:26
Most likely caused by a missing include file or circular includes.Box
is not declared as a type at the point you're getting the error.
– 1201ProgramAlarm
Nov 10 at 14:32
|
show 12 more comments
1
To start with, put a semicolon (;
) after class declarations.
– πάντα ῥεῖ
Nov 10 at 14:01
2
Possibly the definition ofBox
is not in scope. Did you #include the proper file?
– aschepler
Nov 10 at 14:03
1
Indeed, sounds like a missing include.
– Matthieu Brucher
Nov 10 at 14:14
I'd be interested to see the code corresponding to the error messages, and especially theoverride
on the box...
– Christophe
Nov 10 at 14:26
Most likely caused by a missing include file or circular includes.Box
is not declared as a type at the point you're getting the error.
– 1201ProgramAlarm
Nov 10 at 14:32
1
1
To start with, put a semicolon (
;
) after class declarations.– πάντα ῥεῖ
Nov 10 at 14:01
To start with, put a semicolon (
;
) after class declarations.– πάντα ῥεῖ
Nov 10 at 14:01
2
2
Possibly the definition of
Box
is not in scope. Did you #include the proper file?– aschepler
Nov 10 at 14:03
Possibly the definition of
Box
is not in scope. Did you #include the proper file?– aschepler
Nov 10 at 14:03
1
1
Indeed, sounds like a missing include.
– Matthieu Brucher
Nov 10 at 14:14
Indeed, sounds like a missing include.
– Matthieu Brucher
Nov 10 at 14:14
I'd be interested to see the code corresponding to the error messages, and especially the
override
on the box...– Christophe
Nov 10 at 14:26
I'd be interested to see the code corresponding to the error messages, and especially the
override
on the box...– Christophe
Nov 10 at 14:26
Most likely caused by a missing include file or circular includes.
Box
is not declared as a type at the point you're getting the error.– 1201ProgramAlarm
Nov 10 at 14:32
Most likely caused by a missing include file or circular includes.
Box
is not declared as a type at the point you're getting the error.– 1201ProgramAlarm
Nov 10 at 14:32
|
show 12 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Blukennel is a new contributor. Be nice, and check out our Code of Conduct.
Blukennel is a new contributor. Be nice, and check out our Code of Conduct.
Blukennel is a new contributor. Be nice, and check out our Code of Conduct.
Blukennel is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239686%2fhow-to-declare-an-object-of-a-class-within-static-class-c-errors%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
To start with, put a semicolon (
;
) after class declarations.– πάντα ῥεῖ
Nov 10 at 14:01
2
Possibly the definition of
Box
is not in scope. Did you #include the proper file?– aschepler
Nov 10 at 14:03
1
Indeed, sounds like a missing include.
– Matthieu Brucher
Nov 10 at 14:14
I'd be interested to see the code corresponding to the error messages, and especially the
override
on the box...– Christophe
Nov 10 at 14:26
Most likely caused by a missing include file or circular includes.
Box
is not declared as a type at the point you're getting the error.– 1201ProgramAlarm
Nov 10 at 14:32