few questions here

I have a few questions ,here:
      IF you know the answers please do reply:




(1)  Is operator overloading an essential characterestic or objectives of Object oriented
     programming?Is it true that operator overloading in c++ is an example of polymorphism?

(2)  Is there any alternative way for virtual destructors?
    What is the Practical use of virtual constructors?


(3)If a function with the same name and signature defined in both base and derived class

   WITH DIFFERENT RETURN TYPES, WILL it give any error?

   similar to the access types can the modifiers alone be changed ,all others remaining same
  in a derived class?will it give any error?


(4) Is there any data type that cannot used for returning from a function?


(5)Is there any restrictions on the number of members a structure can have?
kesavan_sridharAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abdijCommented:
Answers only:for questions refer above:

1> No Operator overloading is not an essential characteristic of OOPs. (Java (an OOP lang doesnt support it). Yes its true that Operator overloading in C++ is an example of Polymorphism.

2> Call the Base class destructor explicitly to release base class resources if you donot want to have a virtual destructor.
 I have no idea of Vitual constructors existence. Please enlighten me.

3> No both will be considered as different functions. But donot be under impression that you have overridden base class function. Yes modifiers alone can be changed and it will not give any error. But remember the functions are differnt.

4> All the datatypes can be returned.
 (  Except void !!! (to say so literally . You cannot have a "return void"). void is returned by just doing a return !!!).

5> There is no limitations to the number of member a structure can have.

Thanx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jasonclarkeCommented:
Constructors cannot be virtual, because (at least) when a constructor is called all derived classes do not yet exist.  So no methods in a derived class can be called within a constructor.  This can be quite important to be aware of, note:

class A {
public:
   virtual void f() {}
   A() { f(); // Will always call A::f
   }
};

class B : public A {
public:
   virtual void f() {}  // Will not be called
   B() : A() {}
};

A* a = new B;  

It is illegal to have overloaded methods that differ only in return type, consider:

....
int func();
float func();
....
func();  // Which will be called?

The compiler WILL generate an error.

The modifiers can be changed (as long as it is not in just return type).  The usual case of this is for const methods:

int& operator[](size_t s);
const int operator[](size_t s) const;

this pair of methods is OK.  But note the second must be const, because they cannot differ only in return type.
0
LucHoltkampCommented:
1:
An overloaded operator does not need to be virtual (although it usually is), so it is not per definition polymorfism. Only if the keyword virtual is added to a memberfunction, polymorfism (can) be at work

3:
Yes, your returntype may be different, but only if it is also the returntype of the the baseclass function.
BTW, only if you have a compiler that supports the standard, older compilers do not accept this.
For example:
struct A
{
  virtual A* f();
  virtual int g();
};

struct B : A
{
  virtual B* f();       // allowed because a B is a A
  virtual char* g();  // not allowed
};
Luc
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

LucHoltkampCommented:
1:
An overloaded operator does not need to be virtual (although it usually is), so it is not per definition polymorfism. Only if the keyword virtual is added to a memberfunction, polymorfism (can) be at work

3:
Yes, your returntype may be different, but only if it is also the returntype of the the baseclass function.
BTW, only if you have a compiler that supports the standard, older compilers do not accept this.
For example:
struct A
{
  virtual A* f();
  virtual int g();
};

struct B : A
{
  virtual B* f();       // allowed because a B is a A
  virtual char* g();  // not allowed
};
Luc
0
jasonclarkeCommented:
> An overloaded operator does not need to be virtual ...
> so it is not per definition polymorfism

it is not dynamic binding and inheritance polymorphism.  But it is polymorphism in the 'general' sense, all overloading is a kind of 'name' polymorphism where one function name can have multiple, possibly unrelated, implementations.
0
LucHoltkampCommented:
In OOP the parameters are part of the name, so functions with the same identifier but different parameters don't have the same 'name'. And in that sense, it has nothing to do with polymorfism.
0
jasonclarkeCommented:
> so functions with the same identifier > but different parameters don't have
> the same 'name'

at run time they don't have the same time, but as far as the programmer is concerned they do.

If you see an expression a + b, the meaning of '+' is polymorphic in that you need to know the types of the arguments before you can deduce what method will actually be called.

This provides a kind of polymorphism (which merely means that the expression '+' can have multiple implementations - how that 'polymorphism' is implemented by the compiler is irrelevant).
0
KangaRooCommented:
2. Difficult, an alternative would have to determine the actual, runtime type of an object and invoke an apropriate destruction function for it.
2.b There are no virtual constructors. 3. The standard states that a function that is overloaded in a derived class may specify a different return type then the base's function provided that the return type of the original function is a base class off the return type of the overloaded function. <pfoei>
0
kesavan_sridharAuthor Commented:
Thanks for your ideas and for all those who have poured in their

opinions ........sridhar
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.