Do I have to use pointers only?
-
Hi! I just my first semi-project in .NET that combines both MFC and MC++ and it works fine! However, when I needed to use any .NET classes I had to declare them as pointers and pass pointers to methods etc., like this
SqlConnection* s = new SqlConnection();
f (s);Is this the only way it works? :confused: Apparently yes, and I feel sad, I've been using C++ for a while and got used to using references and not pointers.... :rose: Best regards, Alexandru Savescu
-
Hi! I just my first semi-project in .NET that combines both MFC and MC++ and it works fine! However, when I needed to use any .NET classes I had to declare them as pointers and pass pointers to methods etc., like this
SqlConnection* s = new SqlConnection();
f (s);Is this the only way it works? :confused: Apparently yes, and I feel sad, I've been using C++ for a while and got used to using references and not pointers.... :rose: Best regards, Alexandru Savescu
You'll have to create all reference types on the heap. Thus you cannot have a String but only a String*. On the other hand you can have value types on the stack. Nish
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
-
You'll have to create all reference types on the heap. Thus you cannot have a String but only a String*. On the other hand you can have value types on the stack. Nish
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
Thanks Nish, but could you please provide me with some examples with those differences? Thanks. Best regards, Alexandru Savescu
-
Thanks Nish, but could you please provide me with some examples with those differences? Thanks. Best regards, Alexandru Savescu
****Alexpro wrote: Thanks Nish, but could you please provide me with some examples with those differences?
//String has to be on the heap
//It's an __gc class
String *s = new String("hey there");//Point is a value type
Point p = Point(10,19);
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
-
****Alexpro wrote: Thanks Nish, but could you please provide me with some examples with those differences?
//String has to be on the heap
//It's an __gc class
String *s = new String("hey there");//Point is a value type
Point p = Point(10,19);
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
Thanks! I better lookup in the documentation to see the difference between refernce types and value types! :~ Best regards, Alexandru Savescu
-
Thanks! I better lookup in the documentation to see the difference between refernce types and value types! :~ Best regards, Alexandru Savescu
****Alexpro wrote: Thanks! I better lookup in the documentation to see the difference between refernce types and value types! Have fun :-) Nish
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.