Can anyone help me with STL?

Started by
3 comments, last by Real World 22 years, 8 months ago
It's for University and I'ma bit stuck. The lecturer must have issues with me because he refuses to answer my emails for help so I'm hoping someone here can help! I have a C++ class that is like this;

class Vertex{
	public:

		Vertex () {};					//	Constructor
		~Vertex () {};					//	Destructor
		Vertex& build(int);
	
		std::vector<Vector4> shape;						 //		Coordinates of object in each space
		std::vector<Vector4> shapeW;
		std::vector<Vector4> shapeV;
		std::vector<Vector4> shapeP;
		std::vector<Vector4> shapeS;
		
		
};


Vertex& Vertex::build(int i)
{
	shape.resize(i);
	shapeW.resize(i);
	shapeV.resize(i);
	shapeP.resize(i);
	shapeS.resize(i);
	return *this;
}
  
and a Vector4 class that is like this;


class Vector4{
	private:

		float c[4];

	public:

	//constructors
	Vector4(float x=0., float y=0., float z=0., float h=1); //default
};

Vector4::Vector4(float x, float y, float z, float h)
{
	c[0] = x;
	c[1] = y;
	c[2] = z;
	c[3] = h;
}
  
And what I have declared as a global variable is this;

 std::vector<Vertex> object;
  
Which SHOULD be a C++ vector of vectors. The problem I have is when the code tries to reserve memory for the shape.resize(i); part in the build member fuction I get a Visual C++ Assertation error...
quote: Debug Assertation Failed! Program: filename.cpp File: dbgheap.c Line: 1011 Expression: _CrtIsValidHeapPointer(pUserData) for more information on how your program can cause assertation errors.... etc etc. Abort Retry Ignore
If anyone knows what I'm going on about then PLEASE help me because this is very important. I can't see why the code will not work Thanks. If you need any more information then please let me know! Aarrrrrrrggggghhhhhh!!!!! Edited by - Real World on August 9, 2001 10:43:23 AM
Advertisement
OK This BB doesn''t like the "<" tags grr.

Aarrrrrrrggggghhhhhh!!!!!
That fixed it Still need help solving the problem tho if anyones out there
Hi,
It might help if you could explain what the code is actually supposed to do.
Just as a suggestion, try creating a constructor for Vector4 that doesn''t take any arguments (ie Vector4().
I am not sure and am far from documentation but I think that resizeing causes the new elements to be initialised. If there is not a default constructor then it will break. There is a way around this as I think resize can take 2 args.
Regards,
Devore
Sorry I didn''t realise I hadn''t already said what it''s meant to do.

I am trying to create, essentially, a vector of vectors. I need to be able to say OK I want aan "object". This object would have 5 vectors inside each reserved with 40 vector4''s Then I could add another object but this one may only have 10 vector4''s of each type. Or another may have 50

So at anypoint in the program I could say object[0].build[50] and the program would reserve 50 vector4''s in the first object.

Does that make sense?

This topic is closed to new replies.

Advertisement