If I have an array of some class, and that class has const members, is there some way I can call a custom constructor on elements of the array?
I can't seem to reinitialize an element in foos in the example below. A thread on stack overflow mentioned the copy constructor show allow it, but I get "no match for call to '(Foo) (Foo&)'" when I try it.
Code:
class Foo
{
public:
Foo();
Foo(int x, int y);
Foo(const Foo &foo);
private:
const int m_x;
const int m_y;
};
Foo::Foo() : m_x(0),
m_y(0)
{
}
Foo::Foo(int x, int y) : m_x(x),
m_y(y)
{
}
Foo::Foo(const Foo &foo) : m_x(foo.m_x),
m_y(foo.m_y)
{
}
int main()
{
Foo foo;
Foo foo2(2, 3);
Foo foos[10];
foos[0](foo2);
foos[0](2, 3);
foos[0] = Foo(2,3);
return 0;
}