A
AdlerSam
Hi,
please consider the following example:
struct A {
A(int) {}
A() {}
};
struct B {
B(const A &a): _a(a) {}
B(int x, const A &a): _a(a) {}
void f() {}
A _a;
};
int main() {
B v[] = {
B(A(3)),
B(27, A()),
B(A())
};
v[0].f();
v[1].f();
v[2].f();
B x(A(3));
B y(27, A());
B z(A());
x.f();
y.f();
z.f();
}
The last line doesn't compile:
tst.cpp:26: error: request for member ‘f’ in ‘z’, which is of non-
class type ‘B ()(A (*)())’
Obviously, because the compiler thinks that z is a function.
While it is easy to work arround the problem with an intermediate
variable for class B, it annoys me because I need to instantiate a
rather big amount of objects, an I'd like to do it in a table-like
manner.
Thus, my question: Is there a way to tell the compiler that z is an
object while keeping the table-based initialization sceme?
Thanks,
Sam
please consider the following example:
struct A {
A(int) {}
A() {}
};
struct B {
B(const A &a): _a(a) {}
B(int x, const A &a): _a(a) {}
void f() {}
A _a;
};
int main() {
B v[] = {
B(A(3)),
B(27, A()),
B(A())
};
v[0].f();
v[1].f();
v[2].f();
B x(A(3));
B y(27, A());
B z(A());
x.f();
y.f();
z.f();
}
The last line doesn't compile:
tst.cpp:26: error: request for member ‘f’ in ‘z’, which is of non-
class type ‘B ()(A (*)())’
Obviously, because the compiler thinks that z is a function.
While it is easy to work arround the problem with an intermediate
variable for class B, it annoys me because I need to instantiate a
rather big amount of objects, an I'd like to do it in a table-like
manner.
Thus, my question: Is there a way to tell the compiler that z is an
object while keeping the table-based initialization sceme?
Thanks,
Sam