Simple question: Can't I cast to a base class?
Rodrigo de Salvo Braz
braz@students.uiuc.edu
Mon Jan 22 20:10:00 GMT 2001
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
More information about the Gcc
mailing list