Thread: [Dev-C++] Why doesn't this compile?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Andrew V. <av...@in...> - 2002-10-08 19:53:12
|
And more importantly, how can I make it compile?!
#define MY_TYPE IDirect3DBaseTexture8
class CBase
{
public:
CBase() {}
virtual ~CBase() {}
virtual operator MY_TYPE * () = 0;
};
class CDerived : public CBase
{
public:
CDerived() {}
~CDerived() {}
operator MY_TYPE * () { return NULL; }
};
void test()
{
CBase *c = new CDerived();
MY_TYPE *f = c;
}
The #define is there purely so I could see if the code compiled with
different types - it doesn't.
TIA,
Andrew Vidler.
|
|
From: Ioannis V. <no...@ho...> - 2002-10-09 14:54:20
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Andrew Vidler
> Sent: Tuesday, October 08, 2002 10:53 PM
> To: C++ Dev
> Subject: [Dev-C++] Why doesn't this compile?
>=20
>=20
> And more importantly, how can I make it compile?!
>=20
>=20
>=20
> #define MY_TYPE IDirect3DBaseTexture8
>=20
> class CBase
> {
> public:
> CBase() {}
Not needed.
> virtual ~CBase() {}
Or better: virtual ~CBase();
>=20
> virtual operator MY_TYPE * () =3D 0;
Where is IDirect3DBaseTexture8 defined?
> };
>=20
> class CDerived : public CBase
> {
> public:
> CDerived() {}
> ~CDerived() {}
You can ommit the above two.
>=20
> operator MY_TYPE * () { return NULL; }
Better: return 0;
IDirect3DBaseTexture8 not defined anywhere.
> };
>=20
> void test()
> {
> CBase *c =3D new CDerived();
> MY_TYPE *f =3D c;
> }
>=20
>=20
>=20
>=20
> The #define is there purely so I could see if the code compiled with
> different types - it doesn't.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|
|
From: Andrew V. <av...@in...> - 2002-10-09 15:05:30
|
Ummm...MY_TYPE can be any type, change it to "float" if you like,
doesn't make any difference like I said.
I know the constructors etc... aren't strictly needed, they don't stop
it compiling or working though.
Also, the constructors etc... *are* required for the actual
implementation - this is just a stripped down and renamed version for
test perposes.
Oh, and I disagree with the "better to 'return 0'" comment :)
0 is an integer, I know NULL is just #defined as 0, but using NULL
implies a pointer type.
You wouldn't type the following:
UINT I = 27 + NULL;
Would you?, so why write:
UINT *p = 0;
?
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Ioannis
Vranos
Sent: 09 October 2002 15:54
To: 'C++ Dev'
Subject: RE: [Dev-C++] Why doesn't this compile?
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Andrew Vidler
> Sent: Tuesday, October 08, 2002 10:53 PM
> To: C++ Dev
> Subject: [Dev-C++] Why doesn't this compile?
>
>
> And more importantly, how can I make it compile?!
>
>
>
> #define MY_TYPE IDirect3DBaseTexture8
>
> class CBase
> {
> public:
> CBase() {}
Not needed.
> virtual ~CBase() {}
Or better: virtual ~CBase();
>
> virtual operator MY_TYPE * () = 0;
Where is IDirect3DBaseTexture8 defined?
> };
>
> class CDerived : public CBase
> {
> public:
> CDerived() {}
> ~CDerived() {}
You can ommit the above two.
>
> operator MY_TYPE * () { return NULL; }
Better: return 0;
IDirect3DBaseTexture8 not defined anywhere.
> };
>
> void test()
> {
> CBase *c = new CDerived();
> MY_TYPE *f = c;
> }
>
>
>
>
> The #define is there purely so I could see if the code compiled with
> different types - it doesn't.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf _______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Per W. <pw...@ia...> - 2002-10-09 15:28:37
|
Style issues aside.
Correct me if I'm wrong but, your
operator CDerived::MY_TYPE*();
converts from a CDerived object to a MY_TYPE*.
However, you try to use it to convert from a CDerived*.
This would work:
MY_TYPE *p = *c;
/Per W
On Wed, 9 Oct 2002, Andrew Vidler wrote:
> Ummm...MY_TYPE can be any type, change it to "float" if you like,
> doesn't make any difference like I said.
> I know the constructors etc... aren't strictly needed, they don't stop
> it compiling or working though.
> Also, the constructors etc... *are* required for the actual
> implementation - this is just a stripped down and renamed version for
> test perposes.
>
> Oh, and I disagree with the "better to 'return 0'" comment :)
> 0 is an integer, I know NULL is just #defined as 0, but using NULL
> implies a pointer type.
> You wouldn't type the following:
>
> UINT I = 27 + NULL;
>
> Would you?, so why write:
>
> UINT *p = 0;
>
> ?
>
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf Of Ioannis
> Vranos
> Sent: 09 October 2002 15:54
> To: 'C++ Dev'
> Subject: RE: [Dev-C++] Why doesn't this compile?
>
>
> > -----Original Message-----
> > From: dev...@li...
> > [mailto:dev...@li...] On Behalf
> > Of Andrew Vidler
> > Sent: Tuesday, October 08, 2002 10:53 PM
> > To: C++ Dev
> > Subject: [Dev-C++] Why doesn't this compile?
> >
> >
> > And more importantly, how can I make it compile?!
> >
> >
> >
> > #define MY_TYPE IDirect3DBaseTexture8
> >
> > class CBase
> > {
> > public:
> > CBase() {}
>
>
> Not needed.
>
>
> > virtual ~CBase() {}
>
>
> Or better: virtual ~CBase();
>
>
>
> >
> > virtual operator MY_TYPE * () = 0;
>
>
> Where is IDirect3DBaseTexture8 defined?
>
>
>
> > };
> >
> > class CDerived : public CBase
> > {
> > public:
> > CDerived() {}
> > ~CDerived() {}
>
>
> You can ommit the above two.
>
>
> >
> > operator MY_TYPE * () { return NULL; }
>
> Better: return 0;
>
>
> IDirect3DBaseTexture8 not defined anywhere.
>
>
>
> > };
> >
> > void test()
> > {
> > CBase *c = new CDerived();
> > MY_TYPE *f = c;
> > }
> >
> >
> >
> >
> > The #define is there purely so I could see if the code compiled with
> > different types - it doesn't.
>
>
> Ioannis
>
> * Ioannis Vranos
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL: http://run.to/noicys
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Andrew V. <av...@in...> - 2002-10-09 15:36:18
|
Absolutely. Sorry, I'm probably not being very clear :)
MY_TYPE *p = *c
Does work, problem is, what I'm looking for is some operator that does:
MY_TYPE *p = c;
I don't think this is possible...but you never know!
-----Original Message-----
From: Per Westermark [mailto:pw...@ia...]
Sent: 09 October 2002 16:28
To: Andrew Vidler
Cc: 'C++ Dev'
Subject: RE: [Dev-C++] Why doesn't this compile?
Style issues aside.
Correct me if I'm wrong but, your
operator CDerived::MY_TYPE*();
converts from a CDerived object to a MY_TYPE*.
However, you try to use it to convert from a CDerived*.
This would work:
MY_TYPE *p = *c;
/Per W
On Wed, 9 Oct 2002, Andrew Vidler wrote:
> Ummm...MY_TYPE can be any type, change it to "float" if you like,
> doesn't make any difference like I said. I know the constructors
> etc... aren't strictly needed, they don't stop it compiling or working
> though. Also, the constructors etc... *are* required for the actual
> implementation - this is just a stripped down and renamed version for
> test perposes.
>
> Oh, and I disagree with the "better to 'return 0'" comment :) 0 is an
> integer, I know NULL is just #defined as 0, but using NULL implies a
> pointer type. You wouldn't type the following:
>
> UINT I = 27 + NULL;
>
> Would you?, so why write:
>
> UINT *p = 0;
>
> ?
>
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf Of
> Ioannis Vranos
> Sent: 09 October 2002 15:54
> To: 'C++ Dev'
> Subject: RE: [Dev-C++] Why doesn't this compile?
>
>
> > -----Original Message-----
> > From: dev...@li...
> > [mailto:dev...@li...] On Behalf Of
> > Andrew Vidler
> > Sent: Tuesday, October 08, 2002 10:53 PM
> > To: C++ Dev
> > Subject: [Dev-C++] Why doesn't this compile?
> >
> >
> > And more importantly, how can I make it compile?!
> >
> >
> >
> > #define MY_TYPE IDirect3DBaseTexture8
> >
> > class CBase
> > {
> > public:
> > CBase() {}
>
>
> Not needed.
>
>
> > virtual ~CBase() {}
>
>
> Or better: virtual ~CBase();
>
>
>
> >
> > virtual operator MY_TYPE * () = 0;
>
>
> Where is IDirect3DBaseTexture8 defined?
>
>
>
> > };
> >
> > class CDerived : public CBase
> > {
> > public:
> > CDerived() {}
> > ~CDerived() {}
>
>
> You can ommit the above two.
>
>
> >
> > operator MY_TYPE * () { return NULL; }
>
> Better: return 0;
>
>
> IDirect3DBaseTexture8 not defined anywhere.
>
>
>
> > };
> >
> > void test()
> > {
> > CBase *c = new CDerived();
> > MY_TYPE *f = c;
> > }
> >
> >
> >
> >
> > The #define is there purely so I could see if the code compiled with
> > different types - it doesn't.
>
>
> Ioannis
>
> * Ioannis Vranos
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL: http://run.to/noicys
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Ioannis V. <no...@ho...> - 2002-10-09 23:08:19
|
> -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Andrew Vidler > Sent: Wednesday, October 09, 2002 6:36 PM > To: 'C++ Dev' > Subject: RE: [Dev-C++] Why doesn't this compile? >=20 >=20 > Absolutely. Sorry, I'm probably not being very clear :) > MY_TYPE *p =3D *c > Does work, problem is, what I'm looking for is some operator=20 > that does: > MY_TYPE *p =3D c; >=20 > I don't think this is possible...but you never know! Ok you have confused things. Forget the whole thing completely. Just do: // Example #define MY_TYPE int CBase *c =3D new CDerived; If you want to point to it using some pointer of entirely foreign type, this means you must know what you are doing and use a cast (in your case the ugliest of all, reinterpret_cast). MY_TYPE *f =3D reinterpret_cast<MY_TYPE *>(c); Forget those operators you were using. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Ioannis V. <no...@ho...> - 2002-10-09 22:55:48
|
> -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Andrew Vidler > Sent: Wednesday, October 09, 2002 6:05 PM > To: 'C++ Dev' > Subject: RE: [Dev-C++] Why doesn't this compile? >=20 >=20 > Ummm...MY_TYPE can be any type, change it to "float" if you like, > doesn't make any difference like I said. > I know the constructors etc... aren't strictly needed, they don't stop > it compiling or working though. > Also, the constructors etc... *are* required for the actual > implementation - this is just a stripped down and renamed version for > test perposes. >=20 > Oh, and I disagree with the "better to 'return 0'" comment :) > 0 is an integer, I know NULL is just #defined as 0, but using NULL > implies a pointer type. > You wouldn't type the following: >=20 > UINT I =3D 27 + NULL; >=20 > Would you?, so why write: >=20 > UINT *p =3D 0; >=20 > ? "The C++ Programming Language" 3rd Edition or Special Edition (you must have this book): On page 88, 5.1.1. On page 835 the first paragraph. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |