Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cpp . NET: "a->Methodname " vs "a.MethodName"

Tags:

c++-cli

I would like to know the difference between these two (sorry I do not know the name of this subject).

I come from C# where I was used to write System.data as well as classA.MethodA. I have already found out that in Cpp, with namespaces I need to use ::, with classmembers ->. But what about simple "."? I have created System::data:odbc::odbcConnection^ connection. Later I was able to use connection.Open. Why not connection->open?

Im sorry, I am sure its something easily findable on the net, but I dont know english term for these. Thank you guys

like image 520
Gustav Avatar asked Nov 26 '25 00:11

Gustav


1 Answers

If you have a pointer to an object, you use:

MyClass *a = new MyClass();
a->MethodName();

On the other hand, if you have an actual object, you use dotted notation:

MyClass a;
a.MethodName();
like image 77
Pablo Santa Cruz Avatar answered Nov 27 '25 22:11

Pablo Santa Cruz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!