cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Problem using composition.
Problem using composition.
Jun 6, 2017 at 9:34am UTC
Suri96
(2)
The following program shows no output nor it shows any kind of error while compiling. Help me find a solution to it.
#include <iostream>
#include <string>
using namespace std;
class Birthday
{
public:
Birthday(int d, int m, int y)
{
day = d;
month = m;
year = y;
}
void printdate()
{
cout << day << "/" << month << "/" << year << endl;
}
private:
int day;
int month;
int year;
};
class People
{
public:
People(string x, Birthday bo)
:name(x),
dateofbirth(bo)
{
}
void printsomething()
{
cout << name << "birthday is on ";
dateofbirth.printdate();
}
private:
Birthday dateofbirth;
string name;
};
int main()
{
Birthday printbirthday(20,06,1996);
People myself("Surendra",printbirthday );
}
Jun 6, 2017 at 10:13am UTC
MikeyBoy
(5631)
1. Please use code tags when posting code, to make it readable:
http://www.cplusplus.com/articles/z13hAqkS/
2. Your program shows no output, because you're not outputting anything. In your
main
function, you create 2 objects, and then... do nothing at all with them. You don't call any methods on those objects that would output anything.
Jun 6, 2017 at 11:46am UTC
Suri96
(2)
thanks a lot. it completely went out of my mind.
Topic archived. No new replies allowed.