M
mlt
What is the best way to create objects as private fields that take
arguments?
I have class A that contains an instance of class B. In A's constructor I
would like to control a field in B:
class A {
private:
B b;
int size;
public A(){
size = 22;
b = B(size);
}
};
class B{
public B() {}
public B(int s) {
this.size = s;
}
private:
int size;
}
But is there a more elegant way to do this (without using static const int
size)?
arguments?
I have class A that contains an instance of class B. In A's constructor I
would like to control a field in B:
class A {
private:
B b;
int size;
public A(){
size = 22;
b = B(size);
}
};
class B{
public B() {}
public B(int s) {
this.size = s;
}
private:
int size;
}
But is there a more elegant way to do this (without using static const int
size)?