[SOLVED] OOP X not declared! :@

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

[SOLVED] OOP X not declared! :@

Post by VoidElite »

Hey guys I'm getting really p***** off right now with this project! I'm working on a platformer game engine's box collision system and well O.O.P has failed me. :(

Basically the move() function which handles collision checking and movement requires the objects screen and the objects it's checking for collision with. One is of type Base and called base2, but now G++ is telling me that Base is undeclared. But you see the object that is intended to be passed as the operand of move() is also of type Base and named base and that works fine which means that clearly Base exists else lower down the line in Main.h, the declaration of 'Base *base;' wouldn't have been successful. Anyway here's the source code for a few of the files. :)

Globals.h

Code: Select all

//setting bullshit
//setting bullshit
#ifndef GLOBALS_H
#define GLOBALS_H
#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <ctime>
#include "SDL\SDL.h"
#include "Windows.h"

using namespace std;

bool quit;
const int SCREEN_BPP=32;
const int SCREEN_WIDTH=800;
const int SCREEN_HEIGHT=480;
const int SPRITE_MAX=375;
const int SPRITE_WIDTH=32;
const int SPRITE_HEIGHT=32;
const int BASE_HEIGHT=50;
const string SPRITE_FOLDER="Sprites\\";
const string FOREGROUND_FOLDER="Foreground\\";
const string BACKGROUND_FOLDER="Background\\";
const string PLAYER_FOLDER=FOREGROUND_FOLDER+"Player\\";
const string AI_FOLDER=FOREGROUND_FOLDER+"AIs\\";
const string OBJECT_FOLDER=FOREGROUND_FOLDER+"Objects\\";
const string BASE_FOLDER=FOREGROUND_FOLDER+"Bases\\";
const string SKY_FOLDER=BACKGROUND_FOLDER+"Skys\\";
const string PROP_FOLDER=BACKGROUND_FOLDER+"Props\\";
const string BREAK="----------------------------------------------------------------------";

//bullshiz
bool checkCollision(SDL_Rect a,SDL_Rect b);

#include "Debugger.h"
#include "Sprite.cpp"
#include "Player.cpp"
#include "AI.cpp"
#include "Object.cpp"
#include "Base.cpp"
#include "Sky.cpp"
#include "Prop.cpp"
#include "Lib.cpp"
#include "Trigger.cpp"
#endif
Player.h

Code: Select all

#ifndef PLAYER_H
#define PLAYER_H
#include "Globals.h"

using namespace std;

class Player{
	private:
		Sprite *sprite;
		string file;
		int x;
		int y;
		int xDelta;
		int yDelta;
	public:
		Player();
		Player(string file,int x,int y,int w,int h);
		~Player();
		void draw(SDL_Surface *screen);
		void checkInput(SDL_Surface *screen,SDL_Event event2,const int SPRITE_WIDTH,const int SPRITE_HEIGHT);
		void move(SDL_Surface *screen,Base *base2);
		string getFile();
		void setFile(string file2);
		SDL_Rect getBox();
		int getX();
		void setX(int x);
		int getY();
		void setY(int y);
		int getW();
		void setW(int w);
		int getH();
		void setH(int h);
		int getXDelta();
		void setXDelta(int xDelta2);
		int getYDelta();
		void setYDelta(int yDelta2);
};
#endif
Player.cpp

Code: Select all

#ifndef PLAYER_CPP
#define PLAYER_CPP
#include "Player.h"

Player::Player(string file,int x,int y,int w,int h){
	setXDelta(0);
	setYDelta(0);
	sprite=new Sprite(PLAYER_FOLDER+file,x,y,w,h);
}
Player::~Player(){
	delete sprite;
	delete this;
}
void Player::draw(SDL_Surface *screen){
	sprite->draw(screen);
}
void Player::checkInput(SDL_Surface *screen,SDL_Event event2,const int SPRITE_WIDTH,const int SPRITE_HEIGHT){
	//check event
	if(SDL_PollEvent(&event2)){
	if(event2.type==SDL_KEYDOWN){
		switch(event2.key.keysym.sym){
			case SDLK_ESCAPE:
				quit=true;
			break;
			case SDLK_UP: 
				setYDelta(getYDelta()-1);
			break;
            case SDLK_DOWN: 
				setYDelta(getYDelta()+1);
			break;
            case SDLK_LEFT: 	
				setXDelta(getXDelta()-1);
			break;
            case SDLK_RIGHT: 
				setXDelta(getXDelta()+1);
			break;
			default:
				//do nowt
			break;
		}
	}else if(event2.type==SDL_KEYUP){
		switch(event2.key.keysym.sym){
			case SDLK_UP: 
				setYDelta(getYDelta()+1);
			break;
            case SDLK_DOWN: 
				setYDelta(getYDelta()-1);
			break;
            case SDLK_LEFT:
				setXDelta(getXDelta()+1);
			break;
            case SDLK_RIGHT:
				setXDelta(getXDelta()-1);
			break;
			default:
				//do nowt
			break;
		}
	}else if(event2.type==SDL_QUIT){
		quit=true;
	}
	}
}
void Player::move(SDL_Surface *screen,Base *base2){
    setX(getX()+getXDelta());
    if((getX()<0)||(getX()+SPRITE_WIDTH>SCREEN_WIDTH)||(checkCollision(getBox(),base2->getBox()))){
        setX(getX()-getXDelta());
    }
    setY(getY()+getYDelta());
    if((getY()<0)||(getY()+SPRITE_HEIGHT>SCREEN_HEIGHT-BASE_HEIGHT)){
        setY(getY()-getYDelta());
    }
	draw(screen);
}
string Player::getFile(){
	return sprite->getFile();
}
void Player::setFile(string file2){
	sprite->setFile(file2);
}
SDL_Rect Player::getBox(){
	return sprite->getBox();
}
int Player::getX(){
	return sprite->getX();
}
void Player::setX(int x){
	sprite->setX(x);
}
int Player::getY(){
	return sprite->getY();
}
void Player::setY(int y){
	sprite->setY(y);
}
int Player::getW(){
	return sprite->getW();
}
void Player::setW(int w){
	sprite->setW(w);
}
int Player::getH(){
	return sprite->getH();
}
void Player::setH(int h){
	sprite->setH(h);
}
int Player::getXDelta(){
	return xDelta;
}
void Player::setXDelta(int xDelta2){
	xDelta=xDelta2;
}
int Player::getYDelta(){
	return yDelta;
}
void Player::setYDelta(int yDelta2){
	yDelta=yDelta2;
}
#endif
Here are the G++ errors:
In file included from src\Player.cpp:3,
from src\Globals.h:38,
from src\Globals.cpp:3,
from src\Main.h:1,
from src\Main.cpp:1:
src\Player.h:21: error: `Base' has not been declared
src\Player.h:21: error: ISO C++ forbids declaration of `base2' with no type
In file included from src\Globals.h:38,
from src\Globals.cpp:3,
from src\Main.h:1,
from src\Main.cpp:1:
src\Player.cpp:64: error: `Base' has not been declared
src\Player.cpp:64: error: ISO C++ forbids declaration of `base2' with no type
src\Player.cpp: In member function `void Player::move(SDL_Surface*, int*)':
src\Player.cpp:66: error: request for member `getBox' in `*base2', which is of n
on-class type `int'
src\Main.cpp: In function `void foregroundLayer()':
src\Main.cpp:37: error: no matching function for call to `Player::move(SDL_Surfa
ce*&, Base*&)'
src\Player.cpp:64: note: candidates are: void Player::move(SDL_Surface*, int*)
Help appreciated as always. :)
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
User avatar
Milch
Chaos Rift Junior
Chaos Rift Junior
Posts: 241
Joined: Sat Jul 11, 2009 5:55 am
Programming Language of Choice: C++
Location: Austria, Vienna

Re: OOP X not declared! :@

Post by Milch »

Okay, here's what I say:

1. Using a include-guard (the #ifdef part at the beginning of a file) inside a .cpp file is useless (because of point 2)
2. Do not include the .cpp files!

You should only include the .h/.hpp files, and not the .c/.cpp files!
Follow me on twitter!
User avatar
cypher1554R
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1124
Joined: Sun Jun 22, 2008 5:06 pm

Re: OOP X not declared! :@

Post by cypher1554R »

Theoretically, you want to add the .cpp files to the project, but not #include them in code like you do with .h.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: OOP X not declared! :@

Post by Falco Girgis »

More like you failed OOP. ;)

Don't EVER. EVER. #include a CPP file. That's a terrible design practice. That's the same thing as the thread we had here just the other day talking about implementing everything inside of a header file and not using a CPP file...

You are literally recompiling your entire project every time you push build. That defeats the entire purpose of having a linker and using intermediate .o files. You might not care now, but as soon as your project gets any bigger, it's going to be a nightmare.

People have recommended you "add your CPP files to your project." I notice that you're using g++, which makes these recommendations slightly invalid. I remember back in the day, when I was first introduced to GCC/Linux development as well... I'm guessing you're doing this to avoid having to fuck with a makefile? You really need to throw together a very simple makefile invoking g++ for each .cpp file, so that you can simply include the header files. Post here if you need makefile help.
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

Re: OOP X not declared! :@

Post by VoidElite »

GyroVorbis wrote:More like you failed OOP. ;)

Don't EVER. EVER. #include a CPP file. That's a terrible design practice. That's the same thing as the thread we had here just the other day talking about implementing everything inside of a header file and not using a CPP file...

You are literally recompiling your entire project every time you push build. That defeats the entire purpose of having a linker and using intermediate .o files. You might not care now, but as soon as your project gets any bigger, it's going to be a nightmare.

People have recommended you "add your CPP files to your project." I notice that you're using g++, which makes these recommendations slightly invalid. I remember back in the day, when I was first introduced to GCC/Linux development as well... I'm guessing you're doing this to avoid having to fuck with a makefile? You really need to throw together a very simple makefile invoking g++ for each .cpp file, so that you can simply include the header files. Post here if you need makefile help.
Well I was using a build script named build.bat(code):

Code: Select all

@echo off
tools\MinGW\bin\g++.exe src\Main.h -o build\game.exe -lmingw32 -lSDLmain -lSDL
pause
As I don't know how to make a makefile but I could, if that's what your suggesting, compile each file as a .o and link them within the script, would that mean I would completely remove the preprocessor directives? And if so would I have to add any more 'special' code. An example of this task would be nice Falco. :)
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OOP X not declared! :@

Post by N64vSNES »

VoidElite wrote:
GyroVorbis wrote:More like you failed OOP. ;)

Don't EVER. EVER. #include a CPP file. That's a terrible design practice. That's the same thing as the thread we had here just the other day talking about implementing everything inside of a header file and not using a CPP file...

You are literally recompiling your entire project every time you push build. That defeats the entire purpose of having a linker and using intermediate .o files. You might not care now, but as soon as your project gets any bigger, it's going to be a nightmare.

People have recommended you "add your CPP files to your project." I notice that you're using g++, which makes these recommendations slightly invalid. I remember back in the day, when I was first introduced to GCC/Linux development as well... I'm guessing you're doing this to avoid having to fuck with a makefile? You really need to throw together a very simple makefile invoking g++ for each .cpp file, so that you can simply include the header files. Post here if you need makefile help.
Well I was using a build script named build.bat(code):

Code: Select all

@echo off
tools\MinGW\bin\g++.exe src\Main.h -o build\game.exe -lmingw32 -lSDLmain -lSDL
pause
As I don't know how to make a makefile but I could, if that's what your suggesting, compile each file as a .o and link them within the script, would that mean I would completely remove the preprocessor directives? And if so would I have to add any more 'special' code. An example of this task would be nice Falco. :)
Makefiles are daunting at first but you really need to look through some tutorials or maybe you have a book. It'll be a bitch to do but once you've gotten used to them you'll be glad that you looked into it.

As for preprocessor directives, from the makefile you can and specify what gets compiled and linked etc but you'll still need to guard your header files with #ifdef/#ifndef or #pragma once because you don't actually touch the headers from your makefile you'll just include them from your *.cpp files.

This tutorial seems fairly decent:
http://mrbook.org/tutorials/make/
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

Re: OOP X not declared! :@

Post by VoidElite »

N64vSNES wrote:
VoidElite wrote:
GyroVorbis wrote:More like you failed OOP. ;)

Don't EVER. EVER. #include a CPP file. That's a terrible design practice. That's the same thing as the thread we had here just the other day talking about implementing everything inside of a header file and not using a CPP file...

You are literally recompiling your entire project every time you push build. That defeats the entire purpose of having a linker and using intermediate .o files. You might not care now, but as soon as your project gets any bigger, it's going to be a nightmare.

People have recommended you "add your CPP files to your project." I notice that you're using g++, which makes these recommendations slightly invalid. I remember back in the day, when I was first introduced to GCC/Linux development as well... I'm guessing you're doing this to avoid having to fuck with a makefile? You really need to throw together a very simple makefile invoking g++ for each .cpp file, so that you can simply include the header files. Post here if you need makefile help.
Well I was using a build script named build.bat(code):

Code: Select all

@echo off
tools\MinGW\bin\g++.exe src\Main.h -o build\game.exe -lmingw32 -lSDLmain -lSDL
pause
As I don't know how to make a makefile but I could, if that's what your suggesting, compile each file as a .o and link them within the script, would that mean I would completely remove the preprocessor directives? And if so would I have to add any more 'special' code. An example of this task would be nice Falco. :)
Makefiles are daunting at first but you really need to look through some tutorials or maybe you have a book. It'll be a bitch to do but once you've gotten used to them you'll be glad that you looked into it.

As for preprocessor directives, from the makefile you can and specify what gets compiled and linked etc but you'll still need to guard your header files with #ifdef/#ifndef or #pragma once because you don't actually touch the headers from your makefile you'll just include them from your *.cpp files.

This tutorial seems fairly decent:
http://mrbook.org/tutorials/make/
Ok now I'm really f****** confused. :\

I don't get it does my Main.cpp include the headers and the headers include the .cpps or does my Main.cpp include the .cpps and the .cpps include the headers ext.? :\
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: OOP X not declared! :@

Post by dandymcgee »

VoidElite wrote: Ok now I'm really f****** confused. :\

I don't get it does my Main.cpp include the headers and the headers include the .cpps or does my Main.cpp include the .cpps and the .cpps include the headers ext.? :\
Nothing ever includes .cpp files. Both the .cpps and main.cpp should each include the headers it needs.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

Re: OOP X not declared! :@

Post by VoidElite »

dandymcgee wrote:
VoidElite wrote: Ok now I'm really f****** confused. :\

I don't get it does my Main.cpp include the headers and the headers include the .cpps or does my Main.cpp include the .cpps and the .cpps include the headers ext.? :\
Nothing ever includes .cpp files. Both the .cpps and main.cpp should each include the headers it needs.
Yes but what if the X.cpp is used for the initialization of a class, X.h is for the declaration and Main.cpp wants to make an instance of the X class it will require access to X.cpp somehow or do I link the X.cpp with Main.cpp?
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: OOP X not declared! :@

Post by Ginto8 »

for each source file, do this:

Code: Select all

g++ -o x.o -c x.cpp
This will compile each .cpp into a .o object file. Then, do

Code: Select all

g++ -o [executable name] a.o b.o ... x.o
This will link all the object files together into the executable. All interdependencies will be handled this way.

The advantage of this approach (which makefiles use) is that you only have to recompile the object files whose source files (and/or the headers those sources include) have changed. If they haven't, then just link them together again.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OOP X not declared! :@

Post by N64vSNES »

VoidElite wrote: Ok now I'm really f****** confused. :\

I don't get it does my Main.cpp include the headers and the headers include the .cpps or does my Main.cpp include the .cpps and the .cpps include the headers ext.? :\
Don't panic this crap can get very complex I know.

Basically you could do:

Code: Select all

g++ -o Main.cpp -o whatever1.cpp -o whatever2.cpp
etc

But as your project expands and you end up with like for example 80 source files, you really want to type this shit up? And then you also need linker dependencies and other crap on top of this.

A makefile is simply a reference for the compiler so it knows where to go, what to compile, what to link and how this should all get executed.

Just look through that tutorial piece by piece and you'll see it all come together.
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

Re: OOP X not declared! :@

Post by VoidElite »

Ginto8 wrote:for each source file, do this:

Code: Select all

g++ -o x.o -c x.cpp
This will compile each .cpp into a .o object file. Then, do

Code: Select all

g++ -o [executable name] a.o b.o ... x.o
This will link all the object files together into the executable. All interdependencies will be handled this way.

The advantage of this approach (which makefiles use) is that you only have to recompile the object files whose source files (and/or the headers those sources include) have changed. If they haven't, then just link them together again.
I'm still trying to get my head around this stuff. So instead of porting the engine to this new method, I've decided to write a Main.cpp and a X.cpp just for testing. I've been compiling using this Batch script:

Code: Select all

@echo off
set g++=tools\MinGW\bin\g++.exe
%g++% -o bin\X.o -c X.cpp
%g++% -o bin\Main.o -c Main.cpp
%g++% -o game.exe bin\Main.o bin\X.o 
rem -lmingw32 -lSDLmain -lSDL
pause
Here's the code for Main.cpp:

Code: Select all

#include <iostream>

using namespace std;

int main(int argc,char *argv[]){
	Class *myClass=new Class();
	myClass->name="marc";
	cout<<"Hi"<<myClass->name<<endl;
	system("pause");
}
X.cpp:

Code: Select all

class Class{
	public:
		Class();
		char *name;
};
Class::Class(){
	name="Marc";
}
But you see I get this error:

Code: Select all

Main.cpp: In function `int main(int, char**)':
Main.cpp:6: error: `Class' was not declared in this scope
Main.cpp:6: error: `myClass' was not declared in this scope
Main.cpp:6: error: `Class' is not a type
So what modifications do I make to the build script to kinda preprocess X.cpp into Main.cpp without using preprocessor directives?
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OOP X not declared! :@

Post by N64vSNES »

VoidElite wrote:
Ginto8 wrote:for each source file, do this:

Code: Select all

g++ -o x.o -c x.cpp
This will compile each .cpp into a .o object file. Then, do

Code: Select all

g++ -o [executable name] a.o b.o ... x.o
This will link all the object files together into the executable. All interdependencies will be handled this way.

The advantage of this approach (which makefiles use) is that you only have to recompile the object files whose source files (and/or the headers those sources include) have changed. If they haven't, then just link them together again.
I'm still trying to get my head around this stuff. So instead of porting the engine to this new method, I've decided to write a Main.cpp and a X.cpp just for testing.
You mean you're going to forget all about makefiles? Seriously you don't want to skip over that, if you're REALLY that bothered then get a IDE otherwise I very VERY strongly recommend you look into makefiles.
VoidElite wrote: So what modifications do I make to the build script to kinda preprocess X.cpp into Main.cpp without using preprocessor directives?
Why do you want to avoid using preprocessor directives so badly? :|
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

Re: OOP X not declared! :@

Post by VoidElite »

N64vSNES wrote:
VoidElite wrote:
Ginto8 wrote:for each source file, do this:

Code: Select all

g++ -o x.o -c x.cpp
This will compile each .cpp into a .o object file. Then, do

Code: Select all

g++ -o [executable name] a.o b.o ... x.o
This will link all the object files together into the executable. All interdependencies will be handled this way.

The advantage of this approach (which makefiles use) is that you only have to recompile the object files whose source files (and/or the headers those sources include) have changed. If they haven't, then just link them together again.
I'm still trying to get my head around this stuff. So instead of porting the engine to this new method, I've decided to write a Main.cpp and a X.cpp just for testing.
You mean you're going to forget all about makefiles? Seriously you don't want to skip over that, if you're REALLY that bothered then get a IDE otherwise I very VERY strongly recommend you look into makefiles.
VoidElite wrote: So what modifications do I make to the build script to kinda preprocess X.cpp into Main.cpp without using preprocessor directives?
Why do you want to avoid using preprocessor directives so badly? :|
So I should use them? Ahh I sorta understand now. Hey how do I create and use variables in Makefiles?
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OOP X not declared! :@

Post by N64vSNES »

Variables? Off the top of my head I believe they're declared like this:

Code: Select all

my_variable = something_for_example.cpp
And used like such:

Code: Select all

$(my_variable)
Post Reply