compiler error C2440...

G

Guest

I get this:
error C2440: 'initializing' : cannot convert from 'class Day *' to 'class Day'

when I try to compile this:
Day d = new Day();

What is the reason for this? Thanks.

-NH
 
D

Doug Harrison [MVP]

Need said:
I get this:
error C2440: 'initializing' : cannot convert from 'class Day *' to 'class Day'

when I try to compile this:
Day d = new Day();

What is the reason for this? Thanks.

C++ != C#. :)

In C++, you must declare d a pointer:

Day* d = new Day;
d->whatever();

But unless you have a reason to create it dynamically, you're better off
declaring it as below:

Day d;
d.whatever();

This relieves you from worrying about the lifetime of the Day object, which
you must think about given that Day is a non-GC class per your error
message. The second form ensures that d is destroyed when it goes out of
scope.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top