-
Sep 8th, 2004, 04:13 PM
#1
Thread Starter
PowerPoster
Class heirchy within includes problem
Alright, I am understanding of class's and how you can host, parent, child, etc...all those nice given terms for the situations when one class needs another.
Well I have a problem with this structure. See all my class's are in seperate header/source files...
The only information I can find on class's that use parenting and such, define for example 4 different class's within one header, and then I assume write 1 source file for all the function to..maybe 4 source files 1 for each class.
Given that structure I can see how it is easy to go friend this class, and declare a class with public otherclass to use the otherclass public members...all very easy.
But I wish to keep my class's in their seperate header/source files, and yet I need a few class's to be able to borrow functions from a class within a class...I can't get it, does someone want to explain.
I have GameEngine class, which includes my shapes engine header, so i can create an instance of Shapes....Now my SkyBox class needs functions from within Shape class, but I cannot include the shape header cuz I get a redefinition error. I cannot create an instance of the class Shape because it doesn't understand it.......I'm at a loss.
I also had this problem when my FileHandler class needed two structs from within my GameEngine class...I couldn't find a way to get the FileHandler class to read the 2 public structs within GameEngine...so I just got rid of the class and copied all the functions into the GameEngine class....still wish I could make my FileHandler class work...damnit
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Sep 9th, 2004, 10:26 AM
#2
You can include one header from the other. You can use pre-declarations, which simply look like
class classname;
All the buzzt
CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 9th, 2004, 02:26 PM
#3
Thread Starter
PowerPoster
So like a function declaration...
Alright, wish to give me a bleak example
PHP Code:
//one header file
#include "clsShapes.hpp"
#include "clsSky.hpp"
class GameEngine
{
ShapeEngine Shapes;
};
//another header file - clsSky.hpp
class Sky
{
ShapeEngine Shapes;
};
How would I modify this to allow the class sky to compile.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Sep 10th, 2004, 07:04 AM
#4
Put the clsShape include into clsSky, too.
Make sure all your headers have multiple-inclusion-guards. They look like this:
At the head of the file you have:
#ifndef VERY_UNIQUE_SYMBOL_NAME
#define VERY_UNIQUE_SYMBOL_NAME
And at the bottom:
#endif
EDITED!!!!
Because I saw a serious error in my code.
Last edited by CornedBee; Sep 10th, 2004 at 07:58 AM.
All the buzzt
CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 10th, 2004, 07:51 AM
#5
Not NoteMe
Originally posted by CornedBee
They look like this:
At the head of the file you have:
#ifdef VERY_UNIQUE_SYMBOL_NAME
#define VERY_UNIQUE_SYMBOL_NAME
And at the bottom:
#endif
I believe you could also do (at the top of the header to include only once #pragma once as an alternative to that.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts.
-
Sep 10th, 2004, 08:00 AM
#6
#pragma once only works in MSVC++, if you really on it your code will not compile with any other compiler
-
Sep 10th, 2004, 08:01 AM
#7
Yes, but only in VC++.
The MFC wizard generates this useless code:
Code:
#ifndef _SYMBOL_WITH_GUID_
#define _SYMBOL_WITH_GUID_
#if MSC_VER > 0x1200
#pragma once
#endif
...
#endif
This is absolutely idiotic. First, it uses a guard that works everywhere, then it checks if the other guard will work (i.e. it's the MS compiler in a sufficient version) and uses it if so.
Why use the other guard in the first place, then?????
All the buzzt
CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 10th, 2004, 08:04 AM
#8
#pragma once has the (small) advantage that the preprocessor doesn't have to open the file again, it maintains a list of all files included.
-
Sep 10th, 2004, 01:50 PM
#9
Not NoteMe
Thanks for the heads up.
I thought there might be a reason why people don't use it often .
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts.
-
Sep 10th, 2004, 02:51 PM
#10
Addicted Member
Originally posted by Halsafar
So like a function declaration...
Alright, wish to give me a bleak example
PHP Code:
//one header file
#include "clsShapes.hpp"
#include "clsSky.hpp"
class GameEngine
{
ShapeEngine Shapes;
};
//another header file - clsSky.hpp
class Sky
{
ShapeEngine Shapes;
};
How would I modify this to allow the class sky to compile.
how about:
PHP Code:
//another header file - clsSky.hpp
#include "clsGameEngine.hpp"
class Sky
{
ShapeEngine Shapes;
};
and dont forget that either "clsGameEngine.cpp", or "clsGameEngine.lib" (the compiled version), should be available.
well, just as cornedbee said
-
Sep 10th, 2004, 08:30 PM
#11
Thread Starter
PowerPoster
How do I compile my class's cpp file into a lib file?
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Sep 10th, 2004, 11:24 PM
#12
Addicted Member
check the "debug" and "release" folders in ur project directory,
they are full of .obj files.
as much as i know they are similar to .lib, maybe someone else could
do a better job explaining how to use already compiled code.
i just know this is possible as an idea, but nvr did it actually !
because the idea is that, the linker's job is to link one compiled code
with the address of another function compiled in another file,
and add them all up to an exe.
try to mess with project->settings->link->general->object\library modules
Last edited by ZaidGS; Sep 10th, 2004 at 11:33 PM.
-
Sep 11th, 2004, 01:27 AM
#13
If you want to create a .lib (static link library), create a static library project and put all cpps you want in there into it.
All the buzzt
CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|