Problem Blocking operator=

  • Thread starter Mike - EMAIL IGNORED
  • Start date
M

Mike - EMAIL IGNORED

I wrote:

class Parent
{
...
private:
virtual Parent& operator=(const Parent& parent);
};

class Child : public Parent
{
...
private:
virtual Child& operator=(const Child& parent);
};

In neither case was the operator=() defined.

With gcc 3.2, this failed to link, with undefined references
for both operator=(), notwithstanding that it was used nowhere
in my code.

The problem was corrected by removing both "virtual".
Is this expected, or is it a problem with the compiler?

Can anyone cite chapter & verse?

Thanks,
Mike.
 
V

Victor Bazarov

Mike - EMAIL IGNORED said:
I wrote:

class Parent
{
...
private:
virtual Parent& operator=(const Parent& parent);
};

class Child : public Parent
{
...
private:
virtual Child& operator=(const Child& parent);
};

In neither case was the operator=() defined.

With gcc 3.2, this failed to link, with undefined references
for both operator=(), notwithstanding that it was used nowhere
in my code.

The problem was corrected by removing both "virtual".
Is this expected, or is it a problem with the compiler?

Can anyone cite chapter & verse?

10.3/8: A virtual function declared in a class shall be defined,
or declared pure (10.4) in that class, or both; [...]

Victor
 
D

David White

Mike - EMAIL IGNORED said:
I wrote:

class Parent
{
...
private:
virtual Parent& operator=(const Parent& parent);
};

class Child : public Parent
{
...
private:
virtual Child& operator=(const Child& parent);
};

In neither case was the operator=() defined.

With gcc 3.2, this failed to link, with undefined references
for both operator=(), notwithstanding that it was used nowhere
in my code.

I think that's normal for virtual functions. By definition, the call of a
virtual function is decided at run-time, so I suppose the easiest
implementation is to make sure they are there, just in case.
The problem was corrected by removing both "virtual".
Is this expected, or is it a problem with the compiler?

'virtual' is inappropriate anyway because the argument type is different in
each case. Typically, assignment operators are not virtual.

DW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top