This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Simple question: Can't I cast to a base class?


When I compile

#include <iostream>
#include <strstream>

void foo (istream& i) {} 
 
int main (char* argv[], int argc)
{
        foo(istrstream("Simple."));
        return 0;
}

I get:
t.cpp: In function `int main(char **, int)':
t.cpp:8: initialization of non-const reference type `class istream &'
t.cpp:8: from rvalue of type `istrstream'
t.cpp:4: in passing argument 1 of `foo(istream &)'

Shouldn't that work since istrstream is a derived class of istream?
Could anyone please explain that to me?

Thanks,

Rodrigo


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]