Can I do this? it tells me unresolved external symbol WTH!
I really need to initialise the value of GameObjectCount
to Zero
.
Also, when I use the Default constructor to build an object, I cant access any of its members!
WHY?
main.cpp
#pragma once
#include <iostream>
#include <string>
#include "MapTile.h"
#include "GameOb.h"
MapTile backGRIND("Name");
GameOb test();
int main(int, char**){ ////this main is for SDL2////
std::cout << backGRIND.texturePath << std::endl;
std::cout << backGRIND.GameObjectCount << backGRIND.x << backGRIND.ObjectID << std::endl;
GameOb.cpp
#include "GameOb.h"
int GameOb::GameObjectCount = 0;
GameOb::GameOb()
{
GameOb::GameObjectCount++;
GameOb::x = 0;
GameOb::y = 0;
GameOb::ObjectID = GameObjectCount;
GameOb::texturePath = std::string("Ressources/GameObjects/");
std::cout << "Object has been created with Object ID : " << GameOb::ObjectID << std::endl;
}
GameOb::GameOb(int x, int y)
{
GameOb::GameObjectCount++;
GameOb::x = x;
GameOb::y = y;
GameOb::ObjectID = GameObjectCount;
GameOb::texturePath = std::string("Ressources/GameObjects/");
std::cout << "Object has been created with Object ID : " << GameOb::ObjectID << std::endl;
}
GameOb.h
#pragma once
#include <string>
#include <iostream>
class GameOb
{
public:
GameOb();
GameOb(int, int);
~GameOb();
int x;
int y;
int ObjectID;
std::string texturePath;
void update(int, int, int);
static int GameObjectCount;
};
MapTile.cpp
#include "MapTile.h"
MapTile::MapTile(std::string name)
{
GameOb::texturePath += std::string("MapTile/");
}
MapTile::~MapTile()
{
}
MapTile.h
#pragma once
#include <string>
#include <iostream>
#include "GameOb.h"
class MapTile :
public GameOb
{
public:
MapTile(std::string);
~MapTile();
};
OK SO ITS DONE
why cant I access the test instances members?? when i write test.(nothing shows)?? help ... im really new at this.