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

Discussion in 'C++' started by ypjofficial@indiatimes.com, Jan 8, 2006.

  1. Guest

    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 8, 2006
    #1
    1. Advertising

  2. Re: member function definition inside and outside class..functionalready defined error..

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


    /S
    --
    Stefan Naewe
    naewe.s_AT_atlas_DOT_de
    =?ISO-8859-1?Q?Stefan_N=E4we?=, Jan 9, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jianli Shen
    Replies:
    1
    Views:
    555
    Victor Bazarov
    Mar 13, 2005
  2. jt
    Replies:
    13
    Views:
    914
    grahamo
    Apr 5, 2005
  3. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

    Decralation of class inside other class and definition outside this class

    =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki, Jul 13, 2007, in forum: C++
    Replies:
    2
    Views:
    328
    Alf P. Steinbach
    Jul 13, 2007
  4. carlosp
    Replies:
    5
    Views:
    1,197
    EventHelix.com
    Feb 16, 2008
  5. Peter
    Replies:
    8
    Views:
    2,125
    James Kanze
    Dec 20, 2010
Loading...

Share This Page