Hi,

I was curious if I could return a vector from a virtual function. I keep getting an error for this.

Class A
{
public:
virtual vector<int> getSomeStuff();
private:
}

.cpp File
vector<int> A::getsomeStuff()
{
return;
}

Can anyone tell me what I am doing wrong?

misspellings mostly

class A
{
public:
virtual vector<int> getSomeStuff();
private:
};


vector<int> A::getSomeStuff()
{
    vector<int> ay;
return ay;
}

int main()
{
}
Member Avatar for jencas

I prefer

void  A::getSomeStuff(vector<int> & vec)
{
  ...
}

to avoid a possible copy on return.

commented: best solution :) +36
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.