GNU & Borland Pure Virtual Functions.

Jason McDonald jasonm@telefloratech.com
Mon Feb 12 14:05:00 GMT 2001


Sorry, my bad here. If I would have made

void printit(A &a)

to

printit(const A &a)

I would have been OK.

Thanks..

Jason.

At 12:12 PM 2/12/01 -0500, you wrote:
>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



More information about the Gcc mailing list