What is a difference in 'T t = u' and in 'T t( u )'
Hi,
Does anyone can explain me why declarations marked as 1 compile
whereas declarations marked as 2 do not compile?
The most obvious example is the third one with shared_ptr. It is
because of explicite constructor. Am I right?
But what about first and second examples?
Please notice also that examples second and third are completely
different. Constructor calling syntax is right in third but not in
second. However assign syntax is right in second example but not in
third.
#include <boost/assign/list_of.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <vector>
struct S{
S(){}
S( int * ){
std::cout<<"S::S(int *)"<<std::endl;
}
};
struct U{
template< typename T >
operator T * (){
std::cout<<"U::operator T*()"<<std::endl;
return static_cast< T * >( 0 );
}
};
int main(){
{// 1
U u;
S s1( u );
//S s2 = u;
}
{// 2
std::vector< int > array1 = boost::assign::list_of( 2 );
//std::vector< int > array2( boost::assign::list_of( 3 ) );
}
{// 3
boost::shared_ptr< int > p1( new int( 3 ) );
//boost::shared_ptr< int > p2 = new int( 3 );
}
}
Regards,
Lukasz
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]