Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi ,
I have a file in which macros are defined as below:-# define INSTANTIATE_CACHE_X(X_DECL, T) \
template class X_DECL cache_item; \
template class X_DECL vector >; \
template class X_DECL Db_cache; \
T* Db_cache::operator[] (const size_t index) \
{ \
return (*slots)[index].record; \
} \
\
size_t Db_cache::get_cache_size( void ) \
{ \
return slots->size(); \
} \
\
void Db_cache::clear( void ) \
{ \
vector >::iterator slot_i; \
\
for ( slot_i = slots->begin(); slot_i != slots->end(); slot_i++ ) \
{ \
slot_i->query = string(); \
slot_i->row = 0; \
} \
} \
\
Db_cache Db_table::cache;# define INSTANTIATE_CACHE(T) INSTANTIATE_CACHE_X(CLASS_DECL, T)
# define PLUGIN_INSTANTIATE_CACHE(T) INSTANTIATE_CACHE_X(, T)
Now, in another file,macro #2 is being used as -
INSTANTIATE_CACHE(Version)
template class CLASS_DECL Db_table;I am getting following errors:-
[C++ Error] TIVER.CPP(60): E2171 Body has already been defined for
function 'Db_cache::operator [](unsigned int)'
[C++ Error] TIVER.CPP(60): E2171 Body has already been defined for
function 'Db_cache::get_cache_size()'
[C++ Error] TIVER.CPP(60): E2171 Body has already been defined for
function 'Db_cache::clear()'Any solutions are welcome.
Thanks,
Amit

In your macro definition, Db_cache::get_cache_size and void Db_cache::clear are not type specific so the compiler is right in saying you are defining it more than once.
I don't know what the problem is with [] but it is something to do with [] only returning one type. It probably is not allowed.

Thanks for the reply. But, I do not want to make it type specific as this macro is used in different files and by different classes.
However, all are giving the same problem.
So, what should I do ?Thanks,
Amit

I'll need to think about this one. You could try posting it in http://www.codeguru.com/forum/forumdisplay.php?s=&forumid=9
Those guys never seem to sleep so you may get an answer before the weekend is over.

![]() |
jbuilder
|
AutoCad R14
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |