This topic is 4905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have some code that wont compile and I cant figure out why...
class Vertex{
public:
Vector3	p;
double	dU, dV;
};

class Texture{
public:
char	*cName;
Vector3	UAxis;
double	dUShift;
Vector3	VAxis;
double	dVShift;
double	dRotation;
double	dUScale;
double	dVScale;

Texture(){ cName = NULL; }
~Texture(){ if(cName != NULL)delete []cName; }
};

class MapPlane{
public:
Vector3 Verts[3];

MapPlane(){}
~MapPlane(){}
};

class Face{
public:
MapPlane	pnPlane;
Texture		txTexture;

Face(){}
~Face(){}
};

class Brush{
public:
CList<Face,Face&>	FaceList;

Brush(){}
~Brush(){}
};

class Property{
public:
char	*cName;
char	*cValue;

Property(){ cName = NULL; cValue = NULL; }
~Property(){ if(cName != NULL)delete []cName; if(cValue != NULL)delete []cValue; }
};

class Entity{
public:
CList<Property,Property&>	PropertyList;
CList<Brush,Brush&>			BrushList;

Entity(){}
~Entity(){}

};

class MapFile
{
public:
CList<Entity,Entity&> EntityList;

Result	ParseEntity();
Result	ParseProperty();
Result	ParseBrush();
Result	ParseFace();
Result	ParseVector();
Result	ParsePlane();
MapFile();
virtual ~MapFile();
};


Basically the problem arises when I do a list of a list....If I explain it in terms of arrays, u can get the picture... I need an array of unknown size like so....Entity[unknown].face[unknown].vertex[known]... So a number of entities contains a number of faces that contain 3 vertecies. Now I am doing this with linked lists because arrays cannot change size... yet Clist will not allow me to do a list of a list? says this:
c:\sir-x\microsoft visual studio\vc98\mfc\include\afxtempl.h(843) : error C2582: 'Brush' : 'operator =' function is unavailable
c:\sir-x\microsoft visual studio\vc98\include\xlocale(467) : while compiling class-template member function 'struct __POSITION *__thiscall CList<class Brush,class Brush &>::AddTail(class Brush &)'
c:\sir-x\microsoft visual studio\vc98\mfc\include\afxtempl.h(843) : error C2582: 'Entity' : 'operator =' function is unavailable
c:\sir-x\microsoft visual studio\vc98\include\xlocale(467) : while compiling class-template member function 'struct __POSITION *__thiscall CList<class Entity,class Entity &>::AddTail(class Entity &)'
Generating Code...
Error executing cl.exe.



Share on other sites
It would help if you posted the error messages you are getting, saying "it doesn't compile" isn't really that helpfull.

Anyway, I would suspect its todo with trying to store references in CList. Changing those to pointers should help (CList<Face,Face&> -> CList<Face,Face*>).

Alan

Share on other sites
Yea I added it in, u replied too quickly! hah ok ill try that out, Thanks

EDIT: U mean <face*, face*> ?

Share on other sites
Quote:
 U mean ?

That depends. Your original code used the type and a reference to the type. It depends on how CList is implemented (is that your own class?), if you were using std::list I would be able to post exact syntax...

Alan

Share on other sites
im using Clist... and here is my problem.... I have a list of a list of a list and it wont work :(.

SOOOOOOO Im used to using arrays like parent.son[j].grandson.[k]... so that Parents have sons and sons have grandsons... with unknown amounts... Is this possible with lists and if so, could sum1 post me an example? Thanks again,

Share on other sites
considering your using classes with all members public then you may aswell just use struct which is exactly the same except for the default access & inheritance which is public for structs & private for classes, anways here is how you can do it using the standard library list:

#include <string>#include <list>struct Vertex {   Vector3	p;   double	dU, dV;};struct Texture {  std::string   cName;  Vector3	UAxis;  double	dUShift;  Vector3	VAxis;  double	dVShift;  double	dRotation;  double	dUScale;  double	dVScale;};struct MapPlane {   Vector3 Verts[3];};struct Face {   MapPlane	pnPlane;   Texture      txTexture;};struct Brush {    std::list<Face>   FaceList;    };struct Property {   std::string cName;   std::string cValue;};struct Entity {   std::list<Property> PropertyList;   std::list<Brush>    BrushList;};struct MapFile {        std::list<Entity> EntityList;		Result	ParseEntity();	Result	ParseProperty();	Result	ParseBrush();	Result	ParseFace();	Result	ParseVector();	Result	ParsePlane();	void	Load(const std::string& cFileIn);	MapFile();};

Share on other sites
Going back to your original vertex/face/entity example (else Im getting confused switching contexts):

class Face{public:	Vector3 verticies[3];};class Entity{public:	CList < Face * >	faces;};

Then you can create a list of entity's:

CList < Entity * > entities;

Just be aware that these are lists of pointers to the respective types, so you'll need to new them before putting them into the lists. For example:

void Entity::AddFace(Vector3 verts[3]){    Face * face = new Face;    // copy verts to face->verticies    faces.AddTail(face);}

Alan

Share on other sites
Well that makes sence on adding to... but problem is If I create say Face *face = new Face;... then add it, then change face and add it again, then the orignial head is changed because its a pointer...

So like this

Face *face = new Face;
face->pnPlane.x = 7;
face->pnPlane.x = 9;

Face *two = brush->FaceList.GetAt(temp->FaceList.FindIndex(1));

one and two faces will be 9 not 7 and 9 respectivly

Share on other sites
i would say just use the standard library list it will also handle memory management for you, i previously posted an example above with your types.

Share on other sites
Yea I saw the example... I thought u were just changing over to structs... which Right now everything is public and such but that will be changing around, its bare bones and open for ease right now... to get ideas before I build the final route...

That said, How would u access your lists like that? using STD::list's way? Say a usage example.. because the way it looks, it looks exactly like how I am using CList...meaning u cant create lists of lists of lists :( Im lost on it, sorry...

Share on other sites
Quote:
 Original post by xsirxxThat said, How would u access your lists like that?

there are a number of ways the most common way being through iterators.

Quote:
 Original post by xsirxxusing STD::list's way? Say a usage example.. because the way it looks, it looks exactly like how I am using CList...meaning u cant create lists of lists of lists :( Im lost on it, sorry...

yes you can have a std::list of std::list of std::list of some type, try to compile it.

You probably wont to read this it will tell you all you need to know about the standard library containers & algorithms & other STL tidbits.

Share on other sites
here is sample of using STL containers & algorithms:

#include <cmath>#include <iterator>#include <algorithm>#include <list>#include <iostream>int main() {   std::list<int> list_of_ints;   std::generate_n(std::inserter(list_of_ints, list_of_ints.begin()), 20, rand);   std::copy(list_of_ints.begin(), list_of_ints.end(),             std::ostream_iterator<int>(std::cout, ", "));   return 0;}

try it out see if you can guess what it does.

Share on other sites
Listen to snk_kid, he knows whereof he speaks. ^^b