Computing.Net > Forums > Programming > Body defined error in macro in C++

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Body defined error in macro in C++

Reply to Message Icon

Name: Amit Lal
Date: September 26, 2002 at 13:50:44 Pacific
OS: WinXP
CPU/Ram: PIII/128MB
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: cup
Date: September 27, 2002 at 07:47:22 Pacific
Reply:

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.


0

Response Number 2
Name: Amit Lal
Date: September 27, 2002 at 08:36:30 Pacific
Reply:

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


0

Response Number 3
Name: cup
Date: September 27, 2002 at 12:43:12 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More


jbuilder AutoCad R14



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Body defined error in macro in C++

muljtiply defined error in c www.computing.net/answers/programming/muljtiply-defined-error-in-c/16375.html

Body already defined error in C++ www.computing.net/answers/programming/body-already-defined-error-in-c/3612.html

C compile errors in vc++ www.computing.net/answers/programming/c-compile-errors-in-vc/4010.html