|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
So I have this class with a private data member:
const Floor* const destFloor; I need to initialize f, which I'm trying to do in the constructor initializer list: Rider::Rider(const Floor& f) :destFloor(f) { } Here's my error message: Rider.cpp(17) : error C2440: 'initializing' : cannot convert from 'const Floor' to 'const Floor *const ' How do I initialize destFloor? Best Regards, --Hank Stalica |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
"Hank stalica" <me@nospam.net> wrote in message news:69OdnSPz-J1iJY_anZ2dnUVZ_hSdnZ2d@comcast.com... > So I have this class with a private data member: > > const Floor* const destFloor; > > > I need to initialize f, which I'm trying to do in the constructor > initializer list: > > Rider::Rider(const Floor& f) > :destFloor(f) : destFloor(&f) > { > } > > Here's my error message: > > Rider.cpp(17) : error C2440: 'initializing' : cannot convert from 'const > Floor' to 'const Floor *const ' > > How do I initialize destFloor? > > Best Regards, > --Hank Stalica |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Hank stalica wrote:
> So I have this class with a private data member: > > const Floor* const destFloor; > > > I need to initialize f, which I'm trying to do in the constructor > initializer list: > > Rider::Rider(const Floor& f) > :destFloor(f) > { > } > > Here's my error message: > > Rider.cpp(17) : error C2440: 'initializing' : cannot convert from 'const > Floor' to 'const Floor *const ' Well, that's right. You can't initialize a pointer with a reference to the object. > How do I initialize destFloor? Take the address: Rider::Rider(const Floor& f) :destFloor(&f) { } Or just make your member a reference, too. Since you chose to make your pointer const, you can't let it point to anything else later anyway. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Thanks, Jim.
I actually figured that out shortly after posting. Basically, it was one of those things I knew but it was under my nose. Thanks. Jim Langston wrote: > "Hank stalica" <me@nospam.net> wrote in message > news:69OdnSPz-J1iJY_anZ2dnUVZ_hSdnZ2d@comcast.com... >> So I have this class with a private data member: >> >> const Floor* const destFloor; >> >> >> I need to initialize f, which I'm trying to do in the constructor >> initializer list: >> >> Rider::Rider(const Floor& f) >> :destFloor(f) > > : destFloor(&f) > >> { >> } >> >> Here's my error message: >> >> Rider.cpp(17) : error C2440: 'initializing' : cannot convert from 'const >> Floor' to 'const Floor *const ' >> >> How do I initialize destFloor? >> >> Best Regards, >> --Hank Stalica > > |
|
![]() |
| Outils de la discussion | |
|
|