![]() |
| | #1 |
| Registered User Join Date: Dec 2002
Posts: 56
| Problem with operator+ Code: namespace MemoryManager {
enum Option { printall = 1 }; // just one for now
typedef map< void*, Object > pvomap;
class Mgr {
public:
Mgr( Option opt = 0 );
template< class T > T* alloc( int = 1 );
template< class T > void dealloc( T* );
int allocated( const void* ptr ) const;
template< class T > long bytes_allocated ( const T* ) const;
long total_allocated() const;
long total_bytes_allocated() const;
protected:
Option itsOptions;
pvomap allPtrs;
};
} // end namespace MemoryManager
Error E2094: 'operator+' not implemented in type 'pvomap' for arguments of type 'const void *'. Code: int Mgr::allocated( const void* ptr ) const {
Object foo = allPtrs[ ptr ]; // error on this line
int bar = foo.created();
return bar;
}
|
| roktsyntst is offline | |
| | #2 |
| Confused Join Date: Sep 2001 Location: Sweden
Posts: 3,129
| I believe that the [ ] operator works so it takes the base pointer (allPtrs) then adds the relative adress (ptr) to get the effective adress. And thus, const void* doesn't have a + operator defined. Why doing that? Indexes must be integers.
__________________ MagosX.com Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. |
| Magos is offline | |
| | #3 |
| Registered User Join Date: Dec 2002
Posts: 56
| allPtrs is not an array, but rather a std::map with first type "void *". It's subscript operator should be overloaded to take that type and return the associated Object (in this case). What puzzles me is this error ocurring here, but other functions using a similar construct do not report an error. I also forgot to mention that the end of that function reports the following warning: W8057: Parameter 'ptr' is never used in function Mgr::allocated(const void* const). This is also strange, since ptr is clearing being used...I'm guessing there's an obvious syntax error that I'm just missing. |
| roktsyntst is offline | |
| | #4 |
| Skunkmeister Join Date: Aug 2001
Posts: 2,572
| const void * do you know what that is? do you mean void * const
__________________ Free the weed!! Class B to class C is not good enough!! And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi |
| Stoned_Coder is offline | |
| | #5 |
| Registered User Join Date: Dec 2002
Posts: 56
| The difference refers to whether it is the address that is constant or the value there, correct? It probably makes more sense to have void * const, but that doesn't change the issue. A search on comp.lang.c++ (http://groups.google.com/groups?hl=e...5506%40acm.org) revealed that you can't use operator[] on a const map (which is a map that is part of a const object). So I used find instead (at the recommendation there), but that said it could find no match. So I've kept the const-ness of the pointer out completely in order for it to compile... edit: I changed const void* to void* and now to void * const, and it seems to be working. Thanks for the tip. |
| roktsyntst is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| two dot operator problem HELP! | Amyaayaa | C++ Programming | 3 | 03-13-2008 10:45 AM |
| Operator Overloading (Bug, or error in code?) | QuietWhistler | C++ Programming | 2 | 01-25-2006 08:38 AM |
| Serializing problem.. (can't use >> operator) | RancidWannaRiot | Windows Programming | 2 | 10-29-2005 11:10 AM |
| Weird Problem with return with operator + | KonArtis | C++ Programming | 5 | 05-05-2004 03:46 PM |
| problem with new operator | codefx | C++ Programming | 4 | 10-16-2002 05:04 PM |