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. Advertising

  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. Advertising

  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. 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. Iyer, Prasad C

    Overloading __init__ & Function overloading

    Iyer, Prasad C, Sep 30, 2005, in forum: Python
    Replies:
    3
    Views:
    6,438
    Fredrik Lundh
    Sep 30, 2005
  2. Fredrik Lundh
    Replies:
    0
    Views:
    466
    Fredrik Lundh
    Sep 30, 2005
  3. Steve Holden
    Replies:
    0
    Views:
    447
    Steve Holden
    Sep 30, 2005
  4. Iyer, Prasad C
    Replies:
    4
    Views:
    596
    John J. Lee
    Sep 30, 2005
  5. Fredrik Lundh
    Replies:
    0
    Views:
    414
    Fredrik Lundh
    Sep 30, 2005
Loading...

Share This Page