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

Y

ypjofficial

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
 
?

=?ISO-8859-1?Q?Stefan_N=E4we?=

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-lite/inline-functions.html#faq-9.8


/S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top