dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

C++ definēt vektoru

 
dev.gamez.lv Forum Index -> Programmēšana
View previous topic :: View next topic  
Author Message
fest



Joined: 07 Apr 2003
Posts: 187
Location: Madona

PostPosted: Tue Feb 21, 2006 3:13 pm    Post subject: C++ definēt vektoru

Problēma:
Ir fails "SurfaceContainer.h":
Code:

#include "Base.h"
#include <NNEException.h>
class SurfaceContainer
{
private:
   SDL_Surface* mSurf;
   std::string mName;
public:
   SurfaceContainer(const std::string& name, SDL_Surface* surf);
   ~SurfaceContainer(void);
   std::string GetName();
   void SetName(const std::string& name);
   SDL_Surface* GetSurface();
   void SetSurface(SDL_Surface* surf);


};

Un otrs fails:
Code:

#include "Base.h"
#include "SurfaceContainer.h"
class ResourceManager
{
private:
   std::vector<SurfaceContainer> mSurfaces;
[...]


Nu nekādīgi netieku gudrs, kapēc pie rindiņas std::vector<SurfaceContainer> mSurfaces;
VC++2005 Express izmet kļūdu:
Quote:
Compiling...
SurfaceContainer.cpp
c:\fest\kugi\includes\ResourceManager.h(14) : error C2065: 'SurfaceContainer' : undeclared identifier
ResourceManager.cpp

Inklūdošanā problēmu nav.
Droši vien iemesls ir pavisam vienkāršs, bet mans pods to nevar izdomāt ;(
_________________
Signature for rent. Good as new.
4 lines max. 80 letters.
Ls 0,02/post
Back to top
View user's profile Send e-mail
BHC



Joined: 31 Jan 2006
Posts: 81

PostPosted: Tue Feb 21, 2006 4:39 pm    Post subject:

c:\fest\kugi\includes\ResourceManager.h(14) : error C2065: 'SurfaceContainer' : undeclared identifier

Tu taču kļūdu māki izlasīt,
SurfaceContainer nav piedefinēts.

Manuprāt, viens no iemesliem varētu būt "samuģināts, ciklisks inklude". Tas, ka:

Code:


#include "Base.h"
#include <NNEException.h>
class SurfaceContainer
{
private:
   SDL_Surface* mSurf;
   std::string mName;
public:
   SurfaceContainer(const std::string& name, SDL_Surface* surf);
   ~SurfaceContainer(void);
   std::string GetName();
   void SetName(const std::string& name);
   SDL_Surface* GetSurface();
   void SetSurface(SDL_Surface* surf);


};


Base.h inkludē "ResourceManager.h", kas noved pie tā, ka SurfaceContainer tiek definēts pēc ResourceManager.

Uztaisi vienkārši forwārd definīciju.
Kā:
class SurfaceContainer;
class ResourceManager
{
private:
std::vector<SurfaceContainer> mSurfaces;
[...]

Tagad apraksti(inkludē) pašu SurfaceContainer interfeisu.

Citu saprātīgu iemeslu pēc dotā koda nevaru izlobīt.
_________________
Screenshot coming when hell freezes over.


Last edited by BHC on Tue Feb 21, 2006 4:44 pm; edited 1 time in total
Back to top
View user's profile
fest



Joined: 07 Apr 2003
Posts: 187
Location: Madona

PostPosted: Tue Feb 21, 2006 4:44 pm    Post subject:

BHC paldies, tas atrisināja kļūdu Embarassed
_________________
Signature for rent. Good as new.
4 lines max. 80 letters.
Ls 0,02/post
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Tue Feb 21, 2006 4:59 pm    Post subject:

Vai tad forward deklaraacijas var likt lietaa, ja vajadziigi klases pointeri, nevis pashi klases (jaazin tachu klases aiznjemtais izmeers vektoram)?
Back to top
View user's profile Send e-mail
BHC



Joined: 31 Jan 2006
Posts: 81

PostPosted: Tue Feb 21, 2006 5:00 pm    Post subject:

bubu wrote:
Vai tad forward deklaraacijas var likt lietaa, ja vajadziigi klases pointeri, nevis pashi klases (jaazin tachu klases aiznjemtais izmeers vektoram)?

Un vai tad nevar?
_________________
Screenshot coming when hell freezes over.
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Tue Feb 21, 2006 5:08 pm    Post subject:

Var gan, padomaaju un sapratu, ka saputrojos ar vienu citu lietu, ko domaaju.
Back to top
View user's profile Send e-mail
BHC



Joined: 31 Jan 2006
Posts: 81

PostPosted: Tue Feb 21, 2006 5:19 pm    Post subject:

Tu laikam domāji, ka nevar rakstīt šādi:
Code:

class bekons; // deklarējam bekonu
class ruksis
{
        bekons c; // NEVAR, bekons nav definēts
   public:
      void lol()
      {
         int a = sizeof(bekons); // NEVAR, bekons nav definēts
      }            
};

class bekons // piedefinējam bekonu
{

};


Bet var rakstīt šādi:
Code:

class bekons; // bekons deklarējas
class ruksis
{
        bekons * a; // VAR, bet new operātoru gan mēs varēsim izmantot tikai pēc bekona definīcijas, kad zināsim, cik šis garš
   public:
      void lol();      
};
class bekons // bekons tiek definēts
{

};

void ruksis::lol()
{
   int z = sizeof(bekons); // VAR, bekons definēts
   a = new bekons; // VAR, bekons definēts
}


Tā?

Galvenais nejaukt definīciju ar deklerāciju, divi līdzīgi, bet ne vienādi termini. Bieži tiek jaukti.
_________________
Screenshot coming when hell freezes over.
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Wed Feb 22, 2006 10:31 am    Post subject:

Tā arī domāju. Un vēl arī šādi:
Code:
class Bekons;

int funka(Bekons bek)
{
...
}
Back to top
View user's profile Send e-mail
Display posts from previous:   
dev.gamez.lv Forum Index -> Programmēšana All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group