The Version of GCC
bash-3.00$ g++ --version
g++ (GCC) 3.4.5 20051201 (Red Hat 3.4.5-2)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I have got the following errors when I try to compile our project:
c3gtfsevmapmx.cc: In member function `void c3gtfsEventMapper_c::Map3GppManagedBy(CORBA::Any&) const':
c3gtfsevmapmx.cc:616: error: conversion from `const GenericNetworkResourcesIRPSystem::AttributeTypes::MOReferenceSet_var'
to `const GenericNetworkResourcesIRPSystem::AttributeTypes::MOReferenceSet' is ambiguous
/vobs/tao/include/tao/Seq_Var_T.inl:45: note: candidates are: TAO_Seq_Var_Base_T<T, T_elem>::operator const T&() const [with T = GenericNetworkResourcesIRPSystem::AttributeTypes::MOReferenceSet, T_elem = GenericNetworkResourcesIRPSystem::AttributeTypes::MOReference]
/vobs/tao/include/tao/Seq_Var_T.inl:52: note: TAO_Seq_Var_Base_T<T, T_elem>::operator T&() [with T = GenericNetworkResourcesIRPSystem::AttributeTypes::MOReferenceSet, T_elem = GenericNetworkResourcesIRPSystem::AttributeTypes::MOReference] <near match>
/vobs/tao/include/tao/Seq_Var_T.inl:59: note: TAO_Seq_Var_Base_T<T, T_elem>::operator T&() const [with T = GenericNetworkResourcesIRPSystem::AttributeTypes::MOReferenceSet, T_elem = GenericNetworkResourcesIRPSystem::AttributeTypes::MOReference]
The class and functions defined as below:
typedef
TAO_VarSeq_Var_T<
MOReferenceSet,
MOReference
>
MOReferenceSet_var;
template<typename T, typename T_elem>
ACE_INLINE
TAO_Seq_Var_Base_T<T,T_elem>::operator const T & () const
{
return *this->ptr_;
}
template<typename T, typename T_elem>
ACE_INLINE
TAO_Seq_Var_Base_T<T,T_elem>::operator T & ()
{
return *this->ptr_;
}
template<typename T, typename T_elem>
ACE_INLINE
TAO_Seq_Var_Base_T<T,T_elem>::operator T & () const
{
return *this->ptr_;
}
The code fragment at the error point is quite simple:
//CORBA::Any &outAttrSet
//MOReferenceSet_var managedBy
outAttrSet <<= managedBy;
It seems that the assignment operation do not know which operator can be used. Why C++ support such weird methodology?
I have resolved this error by changing the source code to:
outAttrSet <<= managedBy.in();
I am not familiar with CORBA, thus the source code looked like more weird than before.
I have write a simple class to test this trait of C++:
#include <stdlib.h>#include <iostream>using namespace std;class B;class A{public: A() { cout<<"A:::Default constructor "<<endl; }; A(const int n) { cout<<"A:::From const Int "<<endl; }; A(int n) { cout<<"A:::From non-const int"<<endl; } A(const A& a) { cout<<"A:::Copy constructor"<<endl; } A& operator=(const B& b) { cout<<"A:::Operator ="<<endl; } A& operator=(B b) { cout<<"A:::Operator = NONE CONST"<<endl; }};class B{private: A a;public: B(){}; operator A() { cout<<"OPERATOR INT "<<endl; return 1999; }; operator const A() { cout<<"OPERATOR CONST INT "<<endl; return 1999; }; operator const A() const { cout<<"OPERATOR CONST INT CONST "<<endl; return 1999; }; operator A&() { cout<<"OPERATOR INT "<<endl; return a; }; operator const A&() { cout<<"OPERATOR CONST INT "<<endl; return a; }; operator const A&() const { cout<<"OPERATOR CONST INT CONST "<<endl; return a; };};int main(){ cout<<"Begin ......"<<endl; //A aa=A(1); //A a=1;// B b; A c=B();};
As you can see, there are six override operator which have same functionality in class B, I don't know how to use it, and when which a exactly function will be called in certain situation.
C++ is powerful, but have a lot of misconceiver in the methodology, I do not like it.
Another case associated with the compiler is that the compiler do not allow construct a instance like below:
//Class A, A(int)
A a=A(1);//Error occurred at here.
FAINT, Why?