Re: Error C2676 in one function but not another with namespace?
- From: Bruce Stemplewski <Bruce.Stemplewski@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 15 Aug 2005 22:57:25 GMT
Thanks!
Wow how obvious! I feel like an idiot! :)
Scot T Brennecke wrote:
Bruce,
Your problem lies in the fact that you named your parameter Route -- the same as the class. The compiler thinks you are trying to multiply the parameter times something, and hence complains about the binary (two operands) multiplication operator not being defined for that type.
"Bruce Stemplewski" <Bruce.Stemplewski@xxxxxxxxxxxxxxxxxxx> wrote in message news:bwTLe.2492$Hf6.1035@xxxxxxxxxxx
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;
}
}
.
- Follow-Ups:
- Re: Error C2676 in one function but not another with namespace?
- From: Scot T Brennecke
- Re: Error C2676 in one function but not another with namespace?
- References:
- Error C2676 in one function but not another with namespace?
- From: Bruce Stemplewski
- Re: Error C2676 in one function but not another with namespace?
- From: Scot T Brennecke
- Error C2676 in one function but not another with namespace?
- Prev by Date: Re: Moving files in C++ using Windows SDK
- Next by Date: This Do Modal loop - is it safe? Any comments (except, "mmnn, why don't you just use a modal dialog?")
- Previous by thread: Re: Error C2676 in one function but not another with namespace?
- Next by thread: Re: Error C2676 in one function but not another with namespace?
- Index(es):
Relevant Pages
|