Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > overloading in C

Reply
Thread Tools

overloading in C

 
 
uday
Guest
Posts: n/a
 
      11-25-2004
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.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-25-2004
"uday" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
Cheng Mo
Guest
Posts: n/a
 
      12-01-2004
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?


 
Reply With Quote
 
Stuart Gerchick
Guest
Posts: n/a
 
      12-01-2004
Cheng Mo <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
 
Reply With Quote
 
Stuart Gerchick
Guest
Posts: n/a
 
      12-01-2004
"uday" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed) roups.com>...
> 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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      12-01-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Overloading __init__ & Function overloading Iyer, Prasad C Python 4 09-30-2005 08:01 PM
Re: Overloading __init__ & Function overloading Fredrik Lundh Python 0 09-30-2005 03:59 PM
Overloading __init__ & Function overloading Iyer, Prasad C Python 3 09-30-2005 02:17 PM
Re: Overloading __init__ & Function overloading Steve Holden Python 0 09-30-2005 01:58 PM
Re: Overloading __init__ & Function overloading Fredrik Lundh Python 0 09-30-2005 01:53 PM



Advertisments