Can you invoke an instantiated object's class constructor explicity in C++?
You can use placement new, which permits
new (&instance) A(2);
However, from your example you'd be calling a constructor on an object twice which is very bad practice. Instead I'd recommend you just do
A instance(2);
Placement new is usually only used when you need to pre-allocate the memory (e.g. in a custom memory manager) and construct the object later.
No.
Create a method for the set and call it from the constructor. This method will then also be available for later.
class A{
A(int a) { Set(a); }
void Set(int a) { }
}
A instance;
instance.Set(2);
You'll also probably want a default value or default constructor.
No
Calling instance.A() or A(1) is seens as casting 'function-style cast' : illegal as right side of '.' operator
Usually if a function/functionality is to needed in constructor as well as after object is construted it is placed in init() methode and used in constructor and in other place too.
example:
class A{
A(int a)
{
init(a);
}
void init(int a) { }
}
A instance;
instance.init(2);