Suppose I have a non-copyable class Foo, and one of its constructors just gets a link to Foo.
class Foo
{
public:
Foo(Foo& parent) {...}
private:
void operator=(Foo);
...
};
The compiler considers this to be an instance constructor, while it does something completely unrelated to copying (therefore, the assignment operator is disabled).
Is there any danger when defining a constructor this way, or should I change my signature artificially, for example. use a pointer instead of a link, or add a required dummy parameter?
Here is some context (it may not be necessary to understand / answer my question).
, ,
.
, frobnicate .
:
class UsefulObject: public mylib::Frobnicator
{
...
void DoStuff()
{
int x = ...
...
frobnicate(x);
frobnicate(x + 1);
...
}
...
};
: ( )
( , 5) , .
; , ,
.
:
namespace mylib
{
class Frobnicator // provides the frobnication service
{
public:
Frobnicator(Frobnicator& parent): parent(parent) {}
protected:
virtual void frobnicate(int x) {
...
parent->frobnicate(x);
}
private:
Frobnicator& parent;
};
namespace internal
{
class TheUltimateFrobnicator: public Frobnicator
{
protected:
virtual void frobnicate(int x) {
the_other_library::frobnicate(x);
}
private:
TheUltimateFrobnicator(int id);
};
}
}