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]

Re: GNU & Borland Pure Virtual Functions.


On Mon, Feb 12, 2001 at 10:50:00AM -0600, Jason McDonald wrote:
> Hi,
> 
> Why would GNU report an error with this code and Borland Builder would not?
> 
> #include <iostream.h>
> #include <string.h>
> 
> class A{
> public:
>     char temp[10];
>     virtual void from(char *s) { cout << "FROM A";}
>     virtual void blank(void) = 0;
>     virtual ~A(){};
> };
> 
> class B: public A{
> public:
> 
>     virtual void from(char *s) { strcpy(temp,s);}
>     virtual void blank(void) { cout << "BLANK B";}
>     virtual ~B(){};
> };
> 
> B doingB(char *s)
> {
>     B b;
>     b.from(s);
>     return b;
> }
> 
> void printit(A &a)
> {
>     cout << a.temp << " YADA\n";
> }
> 
> int main(void)
> {
>     printit(doingB("THIS"));
>     return 0;
> }
> 
> GNU error:
> >a.c: In function `int main ()':
> >a.c:34: could not convert `doingB()' to `A &'
> >a.c:28: in passing argument 1 of `printit (A &)'

You need to change your code to do this:

int main(void)
{
 B myB = doingB("THIS");
 printit(B);

 return 0;
}

Please read a good C++ book and refer to passing by reference.
-- 
Craig Rodrigues        
http://www.gis.net/~craigr    
rodrigc@mediaone.net          


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