Isn’t
A a = new A(); // A is a class name
supposed to work in C++?
I am getting:
conversion from ‘A*’ to non-scalar
type ‘A’ requested
Whats wrong with that line of code?
This works in Java, right?
Also, what is the correct way to create a new object of type A in C++, then?
No, it isn’t. The new operation returns a pointer to the newly created object, so you need:
You will also need to manage the deletion of the object somewhere else in your code:
However, unlike Java, there is normally no need to create objects dynamically in C++, and whenever possible you should avoid doing so. Instead of the above, you could simply say:
and the compiler will manage the object lifetime for you.
This is extremely basic stuff. Which C++ text book are you using which doesn’t cover it?