It'd be worth checking your book, or an online reference for exactly how to use vectors. There's a brief tutorial on cprogramming.com
http://www.cprogramming.com/tutorial/stl/vector.htmlWhen you declare a vector, you don't need to specify any size - a vector can start out empty, and resize to suit however many objects you add to it. However, you've chosen to pass a size value to the std::vector<Answer>, which would be OK, however the vector is attempting to default-construct 20 Answer objects, and your Answer class has no default constructor.
I can't see any particular reason why you'd want those 20 default constructed Answer objects, so try starting out with an empty vector instead
vector<Answer> answers;You can insert items to the vector at any time using
push_back cpp
Answer my_answer( "forty-two" );
answers.push_back( my_answer );
As for references within a class, you need to use the constructor's initialiser list
cpp
class Question {
public:
string question;
Answer& correctAnswer;
Question(string q,Answer& C) : correctAnswer ( C )
{
correctAnswer=C;
}
This post has been edited by Bench: 7 Jan, 2009 - 02:55 PM