•      Sign In
• Create Account

#Actualpatrrr

Posted 01 August 2012 - 05:54 AM

void setVector(vector<Classname*> &vectorTemp);


You probably want: (notice the const)
void setVector(const vector<Classname*> &vectorTemp);


the function from the class where i get the vector looks like this:

vector<Classname>* getVector()
{
return vector;
}


And here, you probably want
vector<Classname*> &getVector()
{
return vector;
}


or

const vector<Classname*> &getVector() const
{
return vector;
}


or preferably both.

Al-thought if i do this before i send it, everything works:

vector<Classname*> vectorToSend = pointerToClass->getVector();
pointerToClass->setVector(vectorToSend);


You have to do it this way because you can't take a non-const reference to a temporary. Your getVector returns a temporary copy of your vectory (assuming the place where you put the * was a typo), and to be able to send it directly to a function through a reference requires the reference to be const.

#2patrrr

Posted 01 August 2012 - 05:54 AM

void setVector(vector<Classname*> &vectorTemp);


You probably want: (notice the const)
void setVector(const vector<Classname*> &vectorTemp);


the function from the class where i get the vector looks like this:

vector<Classname>* getVector()
{
return vector;
}


And here, you probably want
vector<Classname*> &getVector()
{
return vector;
}


or

const vector<Classname*> &getVector() const
{
return vector;
}


or preferably both.

Al-thought if i do this before i send it, everything works:

vector<Classname*> vectorToSend = pointerToClass->getVector();
pointerToClass->setVector(vectorToSend);


You have to do it this way because you can't take a non-const reference to a temporary. Your getVector returns a temporary copy of your vectory (assuming the place where you put the * was a typo), and to be able to send it directly to a function through a reference requires it to be const.

#1patrrr

Posted 01 August 2012 - 05:51 AM

void setVector(vector<Classname*> &vectorTemp);


You probably want: (notice the const)
void setVector(const vector<Classname*> &vectorTemp);


the function from the class where i get the vector looks like this:

vector<Classname>* getVector()
{
return vector;
}


And here, you probably want
vector<Classname*> &getVector()
{
return vector;
}


or

const vector<Classname*> &getVector() const
{
return vector;
}


or preferably both.

Al-thought if i do this before i send it, everything works:

vector<Classname*> vectorToSend = pointerToClass->getVector();
pointerToClass->setVector(vectorToSend);


You have to do it this way because you can't take a non-const reference to a temporary. Your getVector returns a temporary (assuming the place where you put the * was a typo), and to be able to send it directly to a function through a reference requires it to be const.

PARTNERS