A
Alexander Tumarov
I tried to run next code compiles with g++
//--------------------------------
#include <stdio.h>
class B
{
public:
B& operator=(const B &b)
{
printf("BBBBBBBB \n");
return *this;
};
};
class C
{
public:
C& operator=(const C &c)
{
printf("CCCCCCC \n");
return *this;
};
};
class D : public B,public C
{
public:
D& operator=(const C &c)
{
printf("DDDDDD \n");
return *this;
};
};
int main(int argc, char* argv[])
{
C c1;
D d1,d2;
d1=d2;
d1=c1;
return 0;
}
// --------------------------
And got next output
BBBBBBBB
CCCCCCC
DDDDDD
The question is why compiler builds call to both
B& operator=(const B &b)
C& operator=(const C &c)
on the line
d1=d2;
???
A much as I remember on the case of missing copy operator the compiler
should build default one that performs bit-to-bit copy and not call base
copy operators. Am I wrong?
Can anybody point me to the specific paragraph in the ANSI standard?
Thank you.
//--------------------------------
#include <stdio.h>
class B
{
public:
B& operator=(const B &b)
{
printf("BBBBBBBB \n");
return *this;
};
};
class C
{
public:
C& operator=(const C &c)
{
printf("CCCCCCC \n");
return *this;
};
};
class D : public B,public C
{
public:
D& operator=(const C &c)
{
printf("DDDDDD \n");
return *this;
};
};
int main(int argc, char* argv[])
{
C c1;
D d1,d2;
d1=d2;
d1=c1;
return 0;
}
// --------------------------
And got next output
BBBBBBBB
CCCCCCC
DDDDDD
The question is why compiler builds call to both
B& operator=(const B &b)
C& operator=(const C &c)
on the line
d1=d2;
???
A much as I remember on the case of missing copy operator the compiler
should build default one that performs bit-to-bit copy and not call base
copy operators. Am I wrong?
Can anybody point me to the specific paragraph in the ANSI standard?
Thank you.