B
Bruno Ripa
Hallo,
imagine to have the following simple code:
#include <iostream>
class C
{
public:
C() {}
C( const C & Object )
{
std::cout<<std::endl<<"constant CC !";
}
C( C & )
{
std::cout<<std::endl<<"NON-costant CC!";
}
C & operator = ( const C & Object )
{
std::cout<<std::endl<<"constant =";
}
C & operator = ( C & Object )
{
std::cout<<std::endl<<"NON-costant =";
}
};
C test()
{
C dummy;
return dummy;
}
int main( int argc, char ** argv )
{
C t;
t = test();
return EXIT_SUCCESS;
}
Let's talk about test() function, in particular the 'return dummy'
instruction: should it not invoke a copy constructor to create a copy
of dummy object ?? Instead of this behaviour, i have no cc invoked. I
think it's not that normal!
I'm using g++ 3.3.x under debian, handling the project via Anjuta.
The question is that i have a Matrix class (it represents an image)
that owns a (int *) private member acting as the set of points of the
image.
The question is, having many methods returning a Matrix by value, i
have implemented all of:
Matrix( Matrix & M)
Matrix( const Matrix & M)
M & operator = ( const Matrix &)
M & operator = ( Matrix &)
to be sure to handle what is to be handled regarding the private
pointer (it's a dynamic buffer), but i can't figure which method is
called and i can only get objects with null buffers when methods
return.
Which can be the problem ??? A compiler optimization ??? A bug ???
Thanks in advance,
Bruno Ripa
imagine to have the following simple code:
#include <iostream>
class C
{
public:
C() {}
C( const C & Object )
{
std::cout<<std::endl<<"constant CC !";
}
C( C & )
{
std::cout<<std::endl<<"NON-costant CC!";
}
C & operator = ( const C & Object )
{
std::cout<<std::endl<<"constant =";
}
C & operator = ( C & Object )
{
std::cout<<std::endl<<"NON-costant =";
}
};
C test()
{
C dummy;
return dummy;
}
int main( int argc, char ** argv )
{
C t;
t = test();
return EXIT_SUCCESS;
}
Let's talk about test() function, in particular the 'return dummy'
instruction: should it not invoke a copy constructor to create a copy
of dummy object ?? Instead of this behaviour, i have no cc invoked. I
think it's not that normal!
I'm using g++ 3.3.x under debian, handling the project via Anjuta.
The question is that i have a Matrix class (it represents an image)
that owns a (int *) private member acting as the set of points of the
image.
The question is, having many methods returning a Matrix by value, i
have implemented all of:
Matrix( Matrix & M)
Matrix( const Matrix & M)
M & operator = ( const Matrix &)
M & operator = ( Matrix &)
to be sure to handle what is to be handled regarding the private
pointer (it's a dynamic buffer), but i can't figure which method is
called and i can only get objects with null buffers when methods
return.
Which can be the problem ??? A compiler optimization ??? A bug ???
Thanks in advance,
Bruno Ripa