I have a project will all my classes templated for int, double and float, getCoordinate return an object of the type CCoordinate.
tempCoordinate = m_shapes.at(i)->getCoordinate(j); Before I apply the templates it was working correctly. But then some errors appear.
From what I understand I need I'm missing and operator= overload to typecast the values in case for example that i have a float and I'm receiving an int, for example:
CCoordinate<float> coorFloat; CCoordinate<int> coorInt = coorFloat How can i create this on my class? what format does it need ? .
I was thinking that it should look like this, but apparently i'm mistaken.
//CCoordinate.h template<class T> class CCoordinate { //Code public: template<class U> template <class U> CCoordinate<T> operator= (const CCoordinate<U>& c1); } //CCoordinate.cpp template <class U > CCoordinate<U> CCoordinate<T>::operator= (const CCoordinate<U>& c1) { // some kind of casting ? } My Errors:
19:06:43 **** Incremental Build of configuration Debug for project ShapesRefV2 **** Info: Internal Builder is used for build g++ -O0 -g3 -Wall -c -fmessage-length=0 -Werror=return-type -o "myCode\\CRectangle.o" "..\\myCode\\CRectangle.cpp" g++ -O0 -g3 -Wall -c -fmessage-length=0 -Werror=return-type -o "myCode\\CPlane.o" "..\\myCode\\CPlane.cpp" ..\myCode\CPlane.cpp: In instantiation of 'GraSys::CRectangle<T> GraSys::CPlane<T>::boundingBox(std::string, std::string) [with T = int; std::string = std::basic_string<char>]': ..\myCode\CPlane.cpp:165:24: required from here ..\myCode\CPlane.cpp:115:20: error: no match for 'operator=' (operand types are 'GraSys::CCoordinate<double>' and 'const GraSys::CCoordinate<int>') tempCoordinate = m_shapes.at(i)->getCoordinate(j); ^ ..\myCode\CPlane.cpp:115:20: note: candidate is: In file included from ..\myCode\CGraphicElement.h:14:0, from ..\myCode\CPlane.h:11, from ..\myCode\CPlane.cpp:9: ..\myCode\CCoordinate.h:17:7: note: GraSys::CCoordinate<double>& GraSys::CCoordinate<double>::operator=(const GraSys::CCoordinate<double>&) class CCoordinate ^ ..\myCode\CCoordinate.h:17:7: note: no known conversion for argument 1 from 'const GraSys::CCoordinate<int>' to 'const GraSys::CCoordinate<double>&' ..\myCode\CPlane.cpp: In instantiation of 'GraSys::CRectangle<T> GraSys::CPlane<T>::boundingBox(std::string, std::string) [with T = float; std::string = std::basic_string<char>]': ..\myCode\CPlane.cpp:166:24: required from here ..\myCode\CPlane.cpp:115:20: error: no match for 'operator=' (operand types are 'GraSys::CCoordinate<double>' and 'const GraSys::CCoordinate<float>') tempCoordinate = m_shapes.at(i)->getCoordinate(j); ^ ..\myCode\CPlane.cpp:115:20: note: candidate is: In file included from ..\myCode\CGraphicElement.h:14:0, from ..\myCode\CPlane.h:11, from ..\myCode\CPlane.cpp:9: ..\myCode\CCoordinate.h:17:7: note: GraSys::CCoordinate<double>& GraSys::CCoordinate<double>::operator=(const GraSys::CCoordinate<double>&) class CCoordinate ^ ..\myCode\CCoordinate.h:17:7: note: no known conversion for argument 1 from 'const GraSys::CCoordinate<float>' to 'const GraSys::CCoordinate<double>&' 19:06:44 Build Finished (took 674ms)