For some reason, i cannot get the value of a member from my vector. My compiler tells me this :
"32 C:\My Documents\LIAUNG PRESENTATION\Doopey.cpp
[Warning] the address of `int will always be true"
I tried different combos of asterisks, point tos, and good old spaces, but to no avail. i.e :
The offending functions are GetEndAnswer and GetEndUserAnswer, which just get members from the last element of a vector of Questions. I have no idea why they returns a 1/true/nonzero - they 'should' returnCode:return AllQuestions [ Asked - 1 ].Answer ; return *AllQuestions [ Asked - 1 ]->Answer ; return *AllQuestions [ Asked - 1 ].Answer ;
10 or 20. Is there something i have missed that makes it try to return a pointer or somesuch?
Code:#include <iostream> #include <vector> using namespace std; int Asked = 0; class Question { public : int Answer; int UserAnswer; Question(); }; Question::Question () { Answer = 10; UserAnswer = 20; Asked ++; } vector <Question> AllQuestions; int GetEndAnswer() { return AllQuestions [ Asked - 1 ].Answer; } int GetEndUserAnswer() { return AllQuestions [ Asked - 1 ].UserAnswer; } int main() { AllQuestions.push_back ( Question ); cout << GetEndAnswer << GetEndUserAnswer; system ("PAUSE"); return 0; }



LinkBack URL
About LinkBacks


