objetc o(10);
is equivalent
with
object o = 10;
Only if the constructor isn't declared as explicit:
Code:
#include <iostream>
using namespace std;
class test1 {
int i;
public:
test1(int init)
: i(init)
{}
};
class test2 {
int i;
public:
explicit test2(int init)
: i(init)
{}
};
int
main()
{
test1 a(10); // Okay
test2 b(10); // Okay
test1 c = 10; // Okay
test2 d = 10; // Error! Implicit construction unavailable
}
how can i use "=" in this case
object o(10, 20);
You can't. It only works for constructors that take a single argument. You could manage something similar though by passing an array:
Code:
#include <iostream>
using namespace std;
class test1 {
int i, j;
public:
test1(int init[])
: i(init[0])
, j(init[1])
{}
};
int
main()
{
int args[] = {10, 20};
test1 a = args;
}