This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GNU & Borland Pure Virtual Functions.
- To: Jason McDonald <jasonm at telefloratech dot com>
- Subject: Re: GNU & Borland Pure Virtual Functions.
- From: Craig Rodrigues <rodrigc at mediaone dot net>
- Date: Mon, 12 Feb 2001 12:12:29 -0500
- Cc: gcc at gcc dot gnu dot org
- References: <5.0.0.25.0.20010212104724.00ae4670@mail.telefloratech.com>
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