N
newbie
This is a snippet from C++ FAQs, which I have never done--- when I do
such a thing, I would declare function used by constructor ( in this
example, init() ) as static. But I do understand that it would be
great if the following practice is valid.
But by OO concept, it seems not to very good because init() belongs to
an object, which hasn't be constructed.
Can you give any comment on my question?
class Foo {
public:
Foo(char x);
Foo(char x, int y);
...
private:
void init(char x, int y);
};
Foo::Foo(char x)
{
init(x, int(x) + 7);
...
}
Foo::Foo(char x, int y)
{
init(x, y);
...
}
void Foo::init(char x, int y)
{
...
}
such a thing, I would declare function used by constructor ( in this
example, init() ) as static. But I do understand that it would be
great if the following practice is valid.
But by OO concept, it seems not to very good because init() belongs to
an object, which hasn't be constructed.
Can you give any comment on my question?
class Foo {
public:
Foo(char x);
Foo(char x, int y);
...
private:
void init(char x, int y);
};
Foo::Foo(char x)
{
init(x, int(x) + 7);
...
}
Foo::Foo(char x, int y)
{
init(x, y);
...
}
void Foo::init(char x, int y)
{
...
}