Scenario is I have a function which calls parameterized constructor when I want to initialize. So what I want to do is to call constructor of my choice when I want. But it works when I use A()
to call default constructor but it does not work with a constructor with the parameter rather I am getting following error.
Error 1 error C2082: redefinition of formal parameter 'tmp' c:\users\adnan\documents\visual studio 2012\projects\project3\project3\source.cpp 12 1 Project3
class A
{
public:
int id;
void i(int tmp)
{
A(tmp);
}
A()
{
cout<<"default const"<<endl;
}
A(int id)
{
this->id = id;
}
};
int main()
{
A obj[2];
for(int i=0;i<2;i++)
{
obj[i].i(i*2);
}
cout<<"obj[0].id = "<<obj[0].id;
cout<<endl;
cout<<"obj[1].id = "<<obj[1].id;
cout<<endl;
system("pause");
return 0;
}