I want to display the following message:
**WebPage default constructor called**
**Links default constructor called**
**WebPage default constructor called**
**Links default constructor called**
**WebPage default constructor called**
**Links default constructor called**
**WebPage parameterized constructor called !**
**Links parameterized constructor called !**
**WebSite parameterized constructor called !**
but my code output is
**WebPage default constructor called**
**Links default constructor called**
**WebPage default constructor called**
**Links default constructor called**
**WebPage parameterized called !**
**Links parameterized called !**
**WebPage default constructor called**
**Links default constructor called**
**WebSite parameterized constructor called !**
In short: First 6 lines should print default constructors of webpage and links only while last 3 lines should print parametrized contructor
There is a difference between last 5 lines. I don't know why these are not as expected? Can someone point out at my mistake?
P.S: There is a composition relation between class Webpage, links and website. As webpage and class are composed of website. Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include<iostream>
using namespace std;
class links
{
private:
const char *name;
public:
links()
{
cout<<"\nLinks default constructor called";
}
links(const char *page)
{
cout<<"\nLinks parameterized constructor called!";
}
};
class webpage
{
private:
double width;
double height;
public:
webpage()
{
cout<<"\n\nWebpage default constructor called";
}
webpage(double height,double width)
{
cout<<"\n\nWebpage parameterized constructor called!";
}
};
class website:public webpage,public links
{
private:
char *name1;
webpage a;
links b;
public:
website()
{
}
website(const char *site):webpage(0.5,9.0),links("page")
{
cout<<"\nWebsite parameterized constructor called!";
}
};
int main()
{
website a;
website b("anything");
return 0;
}
|