View Single Post
  #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