I come from a C and C# background. I'm told knowing C# isn't much help in learning C++, as the two are very different.
In C# I would define a class, instantiate some instances, and fill in the data for each instance as needed.
Myclass a = new Myclass;
In C++ I see other ways of instantiating a class:
MyClass* a = new MyClass();
Myclass* a = gcnew Myclass();
class a : MyClass
The last one seems like I'm creating a new class definition for a class named a
, which inherits MyClass, instead of creating an instance of MyClass. Or, since C++ has multiple inheritance and no "implements interface", is the last one better understood as "creating a new class named a
which implements the MyClass interface" (I suppose MyClass would then need to be written as an interface, using pure virtual functions.)
When would I want to use class a : Myclass
instead of Myclass a
I'm also unclear on when to use which:
a.data = 1;
a->data = 1;
a::data = 1;