You are here:

C++/default constructor

Advertisement


Question
#include<iostream>
using namespace std;
int a(int,int);
class p
{
public:
  int i;
  
  p()
  {
     
     cout<<"constructing!!";
  }

  
  ~p(void)
  {
     cout<<"Destructing!....pppp..";
  }
};

class w
{
public:
  int y;
  w(void)
  {
     cout<<"constructing!!";
  }

  ~w(void)
  {
     cout<<"Destructing!....the WWW..";
  }
};

int main()
{
  p ob(p,p,w);
  w ob1;
  
  
  

  return 0;
}
  is there any error?can we send in the declaration any number of object i.e ob(p,p,......)!why is this happening can you tell me?

Answer
   p ob(p,p,w);

Has more than one error.

To start with, p and w are classes (types), not objects (variables).

Even if we had written

   p ob(34,"hello",4.3);

There is an error. The only constructor in class p does not take any arguments.
There is no constructor which can be invoked with three arguments.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++09. i would not answer questions about gui and web programming.

Experience

over 15 years

Education/Credentials
post graduate engineer

©2012 About.com, a part of The New York Times Company. All rights reserved.