I want to use the this pointer to call my constructor within mystation class, it doesn't like this and throws the following error:
Can someone explain to me how the constructor differs to other functions when using the pointerthis to point to the function. I don't want to take the easy way out using |
Many people are asking me why I would want to call the constructor from a function within my class. This is why
I want to have an overloaded constructor so one constructor is parameterless and sets a default values to pass on to my main constructor because managed constructors parameters cannot contain have default values. And I wanted default values for my constructor parameters. Below is my example for further clarity:
#include"stdafx.h"
ref class station{
public:
station(int par_1,int par_2)
{
int sum= par_1 + par_2;
System::Console::WriteLine(System::Convert::ToString(sum));
//default value output 13
};
station(){
int pass_1=5;
int pass_2=8;
station(pass_1,pass_2); /*But why couldn't I use this->station(pass_1,pass_2);*/
};
};
int main(array<System::String^>^
args)
{
station^ obj= gcnew station();
System::Console::ReadLine();
};