|
|
|
|
|
August 18th, 2006, 06:11 PM
|
|
Shrapnel Fanatic
|
|
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
|
|
Re: OT: Stupid c++
Apparently, the compiler tries to treat every .cpp file as a seperate program, so multiple .cpp files do not work. I presume it works with other compilers.
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
|
August 18th, 2006, 06:31 PM
|
|
National Security Advisor
|
|
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
|
|
Re: OT: Stupid c++
C++ is trying to help you to help yourself to write nice code. Why do you want a class member function to have side effects on a global vector defined outside the class?
A nicer way to do it would be to have the constructor take a parameter which tells the object about the global vector (pass it a pointer or reference), store that pointer/reference and use that.
PvK
|
August 18th, 2006, 06:33 PM
|
|
National Security Advisor
|
|
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
|
|
Re: OT: Stupid c++
No, every compiler has limited file scope, to keep globals slightly under control. You can get to objects in other files by declaring them "extern", but relying on globalness tends to get ugly.
|
August 18th, 2006, 06:41 PM
|
|
Shrapnel Fanatic
|
|
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
|
|
Re: OT: Stupid c++
AngleWyrm, what's that code for?
No, just a slight precedence error in 'characterToGraveyard'. I fixed it, but thanks anyway.
@Pvk: Wouldn't that take a lot of memory?
Ah, thanks. The advice makes more sense now.
Update, call it: Simple Roguelike v0.1.4.5
Not a single pointy in the code.
What kind of file is 'main.o'? It's rather big - Can I delete it?
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
|
August 18th, 2006, 08:07 PM
|
|
National Security Advisor
|
|
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
|
|
Re: OT: Stupid c++
It'll use all of 4 bytes if you make it a class static data member, in which case there is only one per class, not per object:
static (STL::vector<cheese>)* pGlobalCheeseVector;
However I guess I'm harping object-oriented design when you are working in a good-ol' C hack design paradigm, which may actually be less confusing for you at this point. If it works and you understand why, it's good code.
main.o is probably an object file. That is, an intermediate file before building the exe. If you delete it, it just means it the compiler will need to recreate it before building the exe, even if you hadn't changed any code in main.cpp before you rebuilt. Generally you can ignore main.o, and you don't need to distribute it to players.
PvK
|
August 18th, 2006, 08:20 PM
|
|
Shrapnel Fanatic
|
|
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
|
|
Re: OT: Stupid c++
Ah, thanks.
Object-oriented design is what I'm trying to do. Any difficulties come because I'm self-taught (Aside from what random people on the internet have taught me).
Er, I've tried to make a pointer to a vector, but it didn't work.
Death to globals!
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
|
August 18th, 2006, 08:33 PM
|
|
National Security Advisor
|
|
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
|
|
Re: OT: Stupid c++
Hmm, a pointer to vector should work - what syntax are you using?
|
August 18th, 2006, 09:09 PM
|
|
Shrapnel Fanatic
|
|
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
|
|
Re: OT: Stupid c++
I dunno. Whatever syntax Dev c/c++ uses. I found a syntax page, but it doesn't list the type.
I'll try it again, soon as I finish getting rid of the current global.
(Er, why did you type STL::vector? I thought it was std?)
This seems to work: 'static std::vector<Character> * CVector;'
So I guess I just put my &Character list vector into CVector, then access that from inside the class?
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
|
August 18th, 2006, 10:05 PM
|
|
National Security Advisor
|
|
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
|
|
Re: OT: Stupid c++
Oh, sorry STL->std (bad human memory).
By "what syntax", I just meant what does your code look like. Yes, the line you wrote is the syntax I was trying to remember and suggest to you. Good job.
Yes, so the syntax for that would be something like:
Code:
// In the class definition file e.g. NarfClass.h
class NarfClass
{
// Constructor:
NarfClass( std::vector<Character> * pCVectorToUse );
// Method that does something with CVector:
void DoStuffWithCVector();
// The static storage of the Character Vector:
static std::vector<Character> * pCVector;
};
Code:
// In the class definition file e.g. NarfClass.cpp
#include "NarfClass.h"
NarfClass::NarfClass( std::vector<Character> * pCVectorToUse )
{
pCVector = pCVectorToUse;
}
void NarfClass:oStuffWithCVector()
{
int NumberOfCharactersInGame = pCVector->size();
// etc...
}
Code:
// In the class that stores the whole gamestate:
#include "NarfClass.h"
// The actual vector:
static std::vector<Character> CVector;
// The creation of a NarfClass object:
NarfClass NarfsNarf( &CVector );
// Now NarfsNarf is an object that can do stuff with CVector.
NarfsNarf.DoStuffWithCVector();
I may have a typo or be missing something, but that's about how I'd do it.
PvK
|
August 18th, 2006, 10:15 PM
|
|
Shrapnel Fanatic
|
|
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
|
|
Re: OT: Stupid c++
Thanks again.
For syntax, I tend to go with the needs of the moment.
So, you mean make a handler class for the Character class?
How do you declare something 'extern'?
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
|
|