This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Simple question: Can't I cast to a base class?
- To: gcc at gcc dot gnu dot org
- Subject: Simple question: Can't I cast to a base class?
- From: Rodrigo de Salvo Braz <braz at students dot uiuc dot edu>
- Date: Mon, 22 Jan 2001 22:09:47 -0600 (CST)
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