Calling class function from my linked list data type

Hi,

Im having a problem with the code below.

First down here is a part of my linklist which consists out of a data type
of class bunny which has its own functions.
"
private:

int counter;
struct node{
bunny x;
node *next;
} *p;"

And when I try to use the display function in the linklist I get compilation errors. Something is wrong with the line "std::cout<<"\n"<<q->x.display();"... Why cant I write like this? I know its that line becuase when I take it
away it compiles without problems. (Note also the simple display function for the bunny class below)

//DISPLAY FUNCTION IN LINKLIST CLASS
void linklist::display(){
node *q;
std::cout<<std::endl;
for(q=p; q != NULL; q=q->next){
std::cout<<"\n"<<q->x.display();
}
}

//DISPLAY FUNCTION IN BUNNY CLASS
void bunny::display(){
std::cout<<sex<<"\n";
std::cout<<name<<"\n";
std::cout<<color<<"\n";
std::cout<<radioactive_mutant_vampire_bunny<<"\n";
}



Answers very appreciated :)
Show the error message and the statemnt where the compiler says that there is the error.
Ok but its really messy. I think the clue in that case must be from the beginning of the error message. Ill cut away 80% of the message :)

g++ -g -Wno-write-strings src/bunny.cpp src/game.cpp src/linklist.cpp src/test.cpp -o my_program
src/linklist.cpp: In member function ‘void linklist::display()’:
src/linklist.cpp:114:42: error: no match for ‘operator<<’ in ‘std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char>&)(& std::cout)), ((const char*)"\012")) << q->linklist::node::x.bunny::display()’
/usr/include/c++/4.5/ostream:108:7: note: candidates are: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/include/c++/4.5/ostream:117:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::op

.......... AND SO ON
Oh crap! I realised it now after 1 hour :P

I cannot put a display function, i.e. q->x.display() in a std::cout line.

If it put that part below it works. Sorry for taking your time.
Can you say what does the statement std::cout<<"\n"<<q->x.display(); mean?!!

Topic archived. No new replies allowed.