Error passing a vector of structure

#define X 0
#define Y 1
#define Z 2

struct GzVertex:public vector<GzReal> {
GzVertex():vector<GzReal>(3, 0) {}
GzVertex(GzReal x, GzReal y, GzReal z):vector<GzReal>(3, 0) {
at(X)=x; at(Y)=y; at(Z)=z;
}
};

#define R 0
#define G 1
#define B 2
#define A 3

struct GzColor:public vector<GzReal> {
GzColor():vector<GzReal>(4, 0) {at(A)=1;}
GzColor(GzReal r, GzReal g, GzReal b):vector<GzReal>(4, 0) {
at(R)=r; at(G)=g; at(B)=b; at(A)=1;
}
GzColor(GzReal r, GzReal g, GzReal b, GzReal a):vector<GzReal>(4, 0) {
at(R)=r; at(G)=g; at(B)=b; at(A)=a;
}
};

I need to create a two vectors one for each struct and pass it to the function below

void GzFrameBuffer::drawTriangle(vector<GzVertex>& v,vector<GzColor>& c, GzFunctional status)

i need to extract three GzVertex and GzColor from thier respective queues and send them to the function frawTriangle. I tried the following code but it was giving me the following error

Error 2 error C2664: 'GzFrameBuffer::drawTriangle' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::vector<_Ty> &' for the last line, when i try to pass the vector to the function drawTraingle. plss help i am a beginner to c++




case GZ_TRIANGLES:
{
GzVertex v;
GzColor c;

vector<vector<GzVertex> > vvs;
vector<GzVertex>vs;
vector<vector<GzColor> > vvc;
vector<GzColor>vc;


while ( (vertexQueue.size()>=1) && (colorQueue.size()>=1) )
{
for(int i=0;i<3;i++)
{
v=vertexQueue.front();
vertexQueue.pop();
vs.push_back(GzVertex(v[X],v[Y],v[Z]));
vvs.push_back(vs);

c=colorQueue.front();
colorQueue.pop();

vc.push_back(GzColor(c[R],c[G],c[B],c[A]));
vvc.push_back(vc);


}
frameBuffer.drawTriangle(vvs,vvc,status);



Also if possible can some one explain me the two structs GzVertex and GzColor.

Thanks
1. The type of vvs is std::vector<std::vector<GzVertex> >. GzFrameBuffer::drawTriangle() expects an std::vector<GzVertex> as its first parameter.
2. Deriving from STL containers is unsafe.
Thank you,

so can i use


frameBuffer.drawTriangle(vs,vc,status); ??
The compiler will accept it. I don't know if it's what you're trying to do.
Basically i want to send a vector holding three GzVertex and three GzColor structs.

what if i want to send an array of vectors?

case GZ_TRIANGLES:
{
GzVertex v;
GzColor c;


vector<GzVertex>vs[3];
vector<GzColor>vc[3];

while ( (vertexQueue.size()>=1) && (colorQueue.size()>=1) )
{
for(int i=0;i<3;i++)
{
v=vertexQueue.front();
vertexQueue.pop();
vs[i].push_back(GzVertex(v[X],v[Y],v[Z]));
//vvs.push_back(vs);

c=colorQueue.front();
colorQueue.pop();

vc[i].push_back(GzColor(c[R],c[G],c[B],c[A]));
//vvc.push_back(vc);


}
frameBuffer.drawTriangle(vs,vc,status);


}

is giving me an error

Error 2 error C2664: 'GzFrameBuffer::drawTriangle' : cannot convert parameter 1 from 'std::vector<_Ty> [3]' to 'std::vector<_Ty> &' c

it may be a basic error but i don't know i am not able to figure it out..

Error 2 error C2664: 'GzFrameBuffer::drawTriangle' : cannot convert parameter 1 from 'std::vector<_Ty> [3]' to 'std::vector<_Ty> &' c


I think the error message is quite clear. You define drawTriangle first parameter to be std::vector<_Ty> & which say reference to ONE vector<_Ty> but when you call it you are passing an array containing 3 vector<_Ty> so of course it don't match.

You need to know what you want out of drawTriangle.

E.g
drawTriangle(std::vector<_Ty> (*v), .....)
drawTriangle(std::vector<_Ty> v[], .....)

yeah got it.. thank you all
Topic archived. No new replies allowed.