473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Initialize a const pointer to a constant object

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
Oct 15 '07 #1
3 4767

"Hank stalica" <me@nospam.netwrote in message
news:69******************************@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

Oct 15 '07 #2
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.

Oct 15 '07 #3
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.netwrote in message
news:69******************************@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

Oct 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: CoolPint | last post by:
Can anyone clearly explain the difference between constant reference to pointers and reference to constant pointers? What is const int * & ? Is it a constant reference to a pointer to an...
74
by: Peter | last post by:
Hi, So many times, I have seen compile warning: "you used a char* without initilize it", probably on the code like this: ------------ char* ptr; func(..., ptr); ----------
11
by: Mantorok Redgormor | last post by:
Is const really constant? And on an OT note: how can I post with a modified e-mail address so I don't get so much spam?
18
by: DaveLessnau | last post by:
I'm trying to learn C on my own and, apparently, my brain went on vacation somewhere. I just can't figure out how to parse the following function call: "void fillDeck( Card * const wDeck, const...
20
by: Snis Pilbor | last post by:
Whats the point of making functions which take arguments of a form like "const char *x"? It appears that this has no effect on the function actually working and doing its job, ie, if the function...
10
by: d3x0xr | last post by:
---- Section 1 ---- ------ x.c int main( void ) { char **a; char const *const *b; b = a; // line(9)
14
by: Tim H | last post by:
I understand the semantics of why this works the way it does. But I wonder if there's a reason for the behaviore at the line marked "QUESTION". I figured if there is an answer, someone here knows...
14
by: Wolfgang | last post by:
As I understand, a const member function is used by const object to ensure that its instance isn't modified throughout its life. Am I missing something.. #include <iostream> using namespace...
10
by: Stephen Howe | last post by:
Hi Just going over some grey areas in my knowledge in C++: 1) If I have const int SomeConst = 1; in a header file, it is global, and it is included in multiple translations units, but it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.