Consider the following :
class A
{
public:
int xx;
A(const A& other)
{
cout << "A cctor" << endl;
/* do some stuff */
}
A(int x) : xx(x) {} /* conversion constructor */
};
int main()
{
A a = 1;
A other = a;
return 0;
}
Is it right to say that CCtor converts from const to non-const in this case (and also in general) ?
Thanks ,Ron
No idea what you mean.
A(const A&)is a typical copy-ctor, which has a “read-only” access to its only argument. If you pass anything const, everything is fine. If you pass anything non-const, for ctor it becomes const.A a = 1is a conversion ctor, as you said.A other = ais a copy ctor. What’s the question?Regarding your question’s title, in C++ there’s no fair way to convert
constto non-const.