Board index » Visual Studio » Error C2676 in one function but not another with namespace?
|
loriinsj
|
Error C2676 in one function but not another with namespace?
Visual Studio332
I am getting the following error in one function of my class but not the other: error C2676: binary '*' : 'GarXface4::Route' does not define this operator or a conversion to a type acceptable to the predefined operator For example if I define: void RouteList::_Add(Route *pRoute) { Route *pRoute1; } This function of the class compiles fine. but if I define: Route* RouteList::Add(Route &Route) { Route* pRoute; return pRoute; } then I get an error C2676. Route and RouteList are both a part of the same namespace. I can get it to compile if I specify the namespace Route* RouteList::Add(Route &Route) { GarXface4::Route* pRoute; return pRoute; } but why should I have too? I have the following header file: namespace GarXface4 { class Route; class Gps; class GARXFACE4_API RouteList { friend Gps; public: RouteList(BOOL bAutoDeleteRoutes = TRUE); ~RouteList(void); Route* Insert(unsigned index, Route &Route); void Remove(unsigned nRoute); void Clear(BOOL bDeleteRoutes=TRUE); Route* Add(Route &Route); unsigned GetCount(); Route *GetRoute(unsigned); protected: void _DeleteRoutes(); void _Add(Route* pRoute); std::vector< Route*>m_coll; BOOL m_bAutoDeleteRoutes; }; } and the following CPP file. namespace GarXface4 { RouteList::RouteList(BOOL bAutoDeleteRoutes) { m_bAutoDeleteRoutes = bAutoDeleteRoutes; } RouteList::~RouteList() { OutputDebugString("GarXface4::RouteList::~RouteList()\n"); if (m_bAutoDeleteRoutes) _DeleteRoutes(); } void RouteList::_Add(Route *pRoute) { m_coll.push_back(pRoute); Route *pRoute1; } Route* RouteList::Add(Route &Route) { Route* p; /* Route* pRoute = new GarXface4::Route; *pRoute = Route; _Add(pRoute); return pRoute; */ return NULL; } Route* RouteList::GetRoute(unsigned index) { //if (index>=m_coll.size()) // throw Exception(GX_ERR_INDEX_OUT_OF_RANGE,FALSE,0); Route* pRoute = m_coll[index]; return pRoute; } unsigned RouteList::GetCount() { return (unsigned)m_coll.size(); } void RouteList::_DeleteRoutes() { unsigned i; unsigned c= (unsigned)m_coll.size(); for (i=0; i<c; i++) { Route *pRoute = m_coll[i]; #if defined _DEBUG char szTemp[256]; sprintf(szTemp,"Deleteing routes %d\n",i); OutputDebugString(szTemp); #endif delete pRoute; } } void RouteList::Clear(BOOL bDeleteRoutes) { if (bDeleteRoutes) _DeleteRoutes(); m_coll.clear(); } void RouteList::Remove(unsigned nRoute) { Route *pRoute = GetRoute(nRoute); delete pRoute; m_coll.erase(m_coll.begin()+nRoute); } Route* RouteList::Insert(unsigned int index, Route& Route) { // if (index>=m_coll.size()) // throw Exception(GX_ERR_INDEX_OUT_OF_RANGE,FALSE,0); GarXface4::Route *pRoute = new GarXface4::Route; *pRoute = Route; m_coll.insert(m_coll.begin()+index,pRoute); return pRoute; } } - |
