Constructor Overloading

Post questions regarding programming in C/C++ in Linux/Unix.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Constructor Overloading

Postby nileshjavar » Tue May 22, 2012 4:23 am

I am using templates, where I instantiate the template for int unsigned types.

Now I want to add another constructor which has a parameter of type int at the same place where the template instantiation for int type has. So there is collision. But I want these two constructors for different implementation.

Example :

template<type>
const1( int a , string b, type c)
{
//Implementation 1
}
The template is instantiated for int , unsigned types. When Instantiated for int type, it is having collision with below implementation where the third parameter is not of a template type but a primitive datatype int

const1(inta, string b, int d)
{
//Implementation 2
}

I really gated here. It would really great if anybody can provide me solution for the above problem.
Thanks in advance
-Nilesh.
nileshjavar
 
Posts: 1
Joined: Tue May 22, 2012 3:52 am

Re: Constructor Overloading

Postby exomo » Wed May 23, 2012 3:07 am

You could rearrange the parameters to get a unique signature, like
Code: Select all
const1(int d, int a, string b)
{
//Implementation 2
}
Who needs a signature anyway.
User avatar
exomo
 
Posts: 879
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden


Return to Unix/Linux

Who is online

Users browsing this forum: No registered users and 1 guest