.com.unity Forums
  The Official e-Store of Shrapnel Games

This Month's Specials

Raging Tiger- Save $9.00
winSPMBT: Main Battle Tank- Save $6.00

   







Go Back   .com.unity Forums > Shrapnel Community > Space Empires: IV & V

Reply
 
Thread Tools Display Modes
  #51  
Old August 18th, 2006, 06:11 PM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default 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.
Reply With Quote
  #52  
Old August 18th, 2006, 06:31 PM
PvK's Avatar

PvK PvK is offline
National Security Advisor
 
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
PvK is on a distinguished road
Default 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
Reply With Quote
  #53  
Old August 18th, 2006, 06:33 PM
PvK's Avatar

PvK PvK is offline
National Security Advisor
 
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
PvK is on a distinguished road
Default 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.
Reply With Quote
  #54  
Old August 18th, 2006, 06:41 PM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default 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.
Reply With Quote
  #55  
Old August 18th, 2006, 08:07 PM
PvK's Avatar

PvK PvK is offline
National Security Advisor
 
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
PvK is on a distinguished road
Default 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
Reply With Quote
  #56  
Old August 18th, 2006, 08:20 PM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default 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.
Reply With Quote
  #57  
Old August 18th, 2006, 08:33 PM
PvK's Avatar

PvK PvK is offline
National Security Advisor
 
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
PvK is on a distinguished road
Default Re: OT: Stupid c++

Hmm, a pointer to vector should work - what syntax are you using?
Reply With Quote
  #58  
Old August 18th, 2006, 09:09 PM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default 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.
Reply With Quote
  #59  
Old August 18th, 2006, 10:05 PM
PvK's Avatar

PvK PvK is offline
National Security Advisor
 
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
PvK is on a distinguished road
Default 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
Reply With Quote
  #60  
Old August 18th, 2006, 10:15 PM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default 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.
Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 04:46 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2024, Shrapnel Games, Inc. - All Rights Reserved.