overloading in C

Discussion in 'C++' started by uday, Nov 25, 2004.

  1. uday

    uday Guest

    Does C supports overloading. I am thinking no. But some people are
    saying yes. If yes how. Please answer with examples.

    Also in c++ size of empty class is one. why. and what are the
    default methods created in a class. These questions are asked in
    interviews. so please explain.
     
    uday, Nov 25, 2004
    #1
    1. Advertisements

  2. "uday" <> wrote...
    > Does C supports overloading. I am thinking no. But some people are
    > saying yes. If yes how. Please answer with examples.


    C does not. And why are you asking about C in a C++ newsgroup?

    > Also in c++ size of empty class is one. why.


    To make sure that an array of such empty class objects would have
    elements sitting at distinct addresses.

    > and what are the
    > default methods created in a class.


    A default constructor, a destructor, a copy constructor, a copy assignment
    operator. Each of them except the destructor are created conditionally.

    > These questions are asked in
    > interviews. so please explain.


    Please read a C++ book for explanations.

    V
     
    Victor Bazarov, Nov 25, 2004
    #2
    1. Advertisements

  3. uday

    Cheng Mo Guest

    Victor Bazarov wrote:
    >>and what are the
    >>default methods created in a class.

    >
    >
    > A default constructor, a destructor, a copy constructor, a copy assignment
    > operator. Each of them except the destructor are created conditionally.
    >
    >

    What doest "conditionally" mean?
    Does it mean that if it is created only when it is used in client code.
    If a class is not used at all. The compiler will not generate default
    constructor, copy constructor and assignemtn operator, right?
     
    Cheng Mo, Dec 1, 2004
    #3
  4. Cheng Mo <> wrote in message news:<>...
    > Victor Bazarov wrote:
    > >>and what are the
    > >>default methods created in a class.

    > >
    > >
    > > A default constructor, a destructor, a copy constructor, a copy assignment
    > > operator. Each of them except the destructor are created conditionally.
    > >
    > >

    > What doest "conditionally" mean?
    > Does it mean that if it is created only when it is used in client code.
    > If a class is not used at all. The compiler will not generate default
    > constructor, copy constructor and assignemtn operator, right?


    That is correct...only if it is used
     
    Stuart Gerchick, Dec 1, 2004
    #4
  5. "uday" <> wrote in message news:<>...
    > Does C supports overloading. I am thinking no. But some people are
    > saying yes. If yes how. Please answer with examples.
    >
    > Also in c++ size of empty class is one. why. and what are the
    > default methods created in a class. These questions are asked in
    > interviews. so please explain.


    C has no overloading. However, using function pointers and setting the
    pointer to different underlying functions, you can duplicate some of
    it, especially if you put the function pointer in a structure and have
    a function to set the pointers in the structure
     
    Stuart Gerchick, Dec 1, 2004
    #5
  6. Cheng Mo wrote:
    > Victor Bazarov wrote:
    >
    >>> and what are the
    >>> default methods created in a class.

    >>
    >>
    >>
    >> A default constructor, a destructor, a copy constructor, a copy
    >> assignment
    >> operator. Each of them except the destructor are created conditionally.
    >>
    >>

    > What doest "conditionally" mean?
    > Does it mean that if it is created only when it is used in client code.
    > If a class is not used at all. The compiler will not generate default
    > constructor, copy constructor and assignemtn operator, right?


    Not just that. The default constructor is not implicitly declared/defined
    if you have any other parameterised constructor in the class. The copy
    c-tor and the copy assignment op cannot be generated in certain cases,
    like having a data member of a reference type, IIRC.

    V
     
    Victor Bazarov, Dec 1, 2004
    #6
    1. Advertisements

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. JJ
    Replies:
    3
    Views:
    2,518
  2. MM

    kinda "overloading"

    MM, Jul 27, 2004, in forum: VHDL
    Replies:
    1
    Views:
    548
    Jonathan Bromley
    Jul 28, 2004
  3. Overloading scope

    , Mar 27, 2006, in forum: VHDL
    Replies:
    1
    Views:
    590
    Mike Treseler
    Mar 27, 2006
  4. Edward Diener

    Delegate overloading

    Edward Diener, Dec 4, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,112
    Chris Jackson
    Dec 4, 2003
  5. shalafi

    Overloading the = in c#

    shalafi, Jun 29, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    799
  6. sk
    Replies:
    5
    Views:
    2,453
    Shardul Kulkarni
    Mar 10, 2005
  7. Iyer, Prasad C

    Overloading __init__ & Function overloading

    Iyer, Prasad C, Sep 30, 2005, in forum: Python
    Replies:
    3
    Views:
    6,648
    Fredrik Lundh
    Sep 30, 2005
  8. Iyer, Prasad C
    Replies:
    4
    Views:
    770
    John J. Lee
    Sep 30, 2005
Loading...