By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

Problem Blocking operator=

P: n/a
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.
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Mike - EMAIL IGNORED" <m_*************@yahoo.com> wrote...
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
Jul 22 '05 #2

P: n/a
"Mike - EMAIL IGNORED" <m_*************@yahoo.com> wrote in message
news:3F***************@yahoo.com...
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

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.