overloading in C

U

uday

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

Victor Bazarov

uday said:
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
 
C

Cheng Mo

Victor said:
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?
 
S

Stuart Gerchick

Cheng Mo said:
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
 
S

Stuart Gerchick

uday said:
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
 
V

Victor Bazarov

Cheng said:
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
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top