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: ')'










share|improve this question









New contributor




Blukennel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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















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: ')'










share|improve this question









New contributor




Blukennel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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













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: ')'










share|improve this question









New contributor




Blukennel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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++






share|improve this question









New contributor




Blukennel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Blukennel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 10 at 14:51





















New contributor




Blukennel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 10 at 13:57









Blukennel

11




11




New contributor




Blukennel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Blukennel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Blukennel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 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














  • 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








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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Blukennel is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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





































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.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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




















































































Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation