471,579 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,579 software developers and data experts.

member function definition inside and outside class..function already defined error..

Hi all,

what's difference does it make when we define the member function
inside and outside a class?

I am using vc7.
when i define the member functions outside a class with the scope
resolution operator and put everything inside a .h file (also note that
i have put the include guard to avoid multiple inclusion of the same
header file accedently ) and include this file in multiple source file
from a same project then i get the error of "function already defined
in some *.obj file.."
so to avoid that now when i put all the member function definitions
inside a class the same project compiles successfully...
could any please tell me the reason behind this behaviour?
Regards,
Yogesh Joshi

Jan 9 '06 #1
1 4283
yp*********@indiatimes.com wrote:
Hi all,

what's difference does it make when we define the member function
inside and outside a class?

I am using vc7.
when i define the member functions outside a class with the scope
resolution operator and put everything inside a .h file (also note that
i have put the include guard to avoid multiple inclusion of the same
header file accedently ) and include this file in multiple source file
from a same project then i get the error of "function already defined
in some *.obj file.."
so to avoid that now when i put all the member function definitions
inside a class the same project compiles successfully...
could any please tell me the reason behind this behaviour?
Regards,
Yogesh Joshi


To define the member function in the .h file, use:

inline
return_type Class::Function(arg_t arg)
{
}

Member functions defined inside the class declaration are implicitly
inline.

See: http://www.parashift.com/c++-faq-lit...s.html#faq-9.8
/S
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Jan 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bo Sun | last post: by
5 posts views Thread by rossum | last post: by
3 posts views Thread by Tran Tuan Anh | last post: by
5 posts views Thread by Martin Vorbrodt | last post: by
10 posts views Thread by stonny | last post: by
21 posts views Thread by H9XLrv5oXVNvHiUI | last post: by
4 posts views Thread by aaragon | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.