#ifndef _CORE_H_
#define _CORE_H_
#include "CSnake\Snake.h"
class Core
{
CSnake snake(30,30); // THE ERROR IS HERE
public:
Core();
int idleEvents();
};
I did a fully working snake class ( which was working on a windows console app )
My problem is, that when i declair CSnake snake(30,30) in my new game Core class there is an error : error C2059: syntax error : 'constant'
Can't I creat instancess in within the class's defenition ??
class Core{ CSnake snake;//declare snake is a member herepublic: Core() : snake(30, 30) {//snake is constructed here, in the constructor (c: } int idleEvents();};
Try this:
I think you are trying to initialize the CSnake instance too early, my modification just moves that into the constructor, so snake will be initialized as soon as you create the Core.
[edit]I see petewood beat me to it.[/edit]
Hope this helps,
SwiftCoder
#ifndef _CORE_H_#define _CORE_H_#include "CSnake\Snake.h"class Core{CSnake snake;public: Core() : snake(30,30) {} int idleEvents();};
I think you are trying to initialize the CSnake instance too early, my modification just moves that into the constructor, so snake will be initialized as soon as you create the Core.
[edit]I see petewood beat me to it.[/edit]
Hope this helps,
SwiftCoder
I have changed the code to this, but i get this error:
"WinSnake error LNK2019: unresolved external symbol "public: __thiscall CSnake::CSnake(int,int)" (??0CSnake@@QAE@HH@Z) referenced in function "public: __thiscall Core::Core(void)" (??0Core@@QAE@XZ)
"
Like I said, the snake class is fully working. What am I doing wrong ???
Even if do just this :
The compiler gives me 2 erros
WinSnake error LNK2019: unresolved external symbol "public: __thiscall CSnake::CSnake(void)" (??0CSnake@@QAE@XZ) referenced in function "public: __thiscall Core::Core(void)" (??0Core@@QAE@XZ)
and
WinSnake fatal error LNK1120: 1 unresolved externals
"WinSnake error LNK2019: unresolved external symbol "public: __thiscall CSnake::CSnake(int,int)" (??0CSnake@@QAE@HH@Z) referenced in function "public: __thiscall Core::Core(void)" (??0Core@@QAE@XZ)
"
Like I said, the snake class is fully working. What am I doing wrong ???
#ifndef _CORE_H_#define _CORE_H_#include "CSnake\Snake.h"class Core{ CSnake snake; public: Core():snake(50,50) { }; int idleEvents(); };#endif
Even if do just this :
#ifndef _CORE_H_#define _CORE_H_#include "CSnake\Snake.h"class Core{ CSnake snake; public: Core() { }; int idleEvents(); };#endif
The compiler gives me 2 erros
WinSnake error LNK2019: unresolved external symbol "public: __thiscall CSnake::CSnake(void)" (??0CSnake@@QAE@XZ) referenced in function "public: __thiscall Core::Core(void)" (??0Core@@QAE@XZ)
and
WinSnake fatal error LNK1120: 1 unresolved externals
Quote:Original post by Anonymous Poster
It's a linker error, so his constructors probably don't have any bodies.
Good point. I missed that...
Here are the relevant files:
core.h
core.cpp
snake.h
core.h
#ifndef _CORE_H_#define _CORE_H_#include "CSnake\\Snake.h"class Core{ CSnake snake; public: Core() { }; int idleEvents(); };#endif
core.cpp
#include "Core.h"/*idleEvents : this is where the idle events of the game would accure.Events and Game states which happen when there is no input.*/int Core::idleEvents(){ return 1;}/*Core::Core():snake(50,50) // the construcots body is in the core.h now{ }*/
snake.h
#ifndef SNAKE_H#define SNAKE_H#include "MCPoint.h"#include "CNode.h"#include "CList.h"#define FREE_BLOCK 0#define BORDER_BLOCK 1#define FOOD_BLOCK 2#define SNAKE_BLOCK 3#define NORTH 0#define EAST 1#define SOUTH 2#define WEST 3class CSnake{public: int L,H;// Length , Heigth int direction;// the direction of the snake int map[100][100];//map matrix CList snake;// the snake is a linked list CSnake(int,int); CSnake(); void setMapDimantion(int len,int hig); void initMap(); void setSnake(MCPoint); bool updateSnake();// update the snakes movement by the member variable: direction int checkNextBlock(); int checkThisBlock(MCPoint); // generate food block MCPoint getRandomFreeBlock();//looks for a FREE_BLOCK at a random spot at the map void addFoodBlock();//adds a food block to the map private: // Linked List related functions void flip();// replaces the head with the tail void progressSnake(); };#endif
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement