2000行之motherfatherchild

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2000行之motherfatherchild相关的知识,希望对你有一定的参考价值。

//child.h
#ifndef CHILD_H
#define CHILD_H
#include <string>
using namespace std;
class Mother;
class Father;
class Child
{
public:
    Mother *mama;
    Father *baba;
    Child();
    string name;
    void answer();
    void callParent();
};

#endif // CHILD_H
//child.cpp
#include "child.h"
#include "mother.h"
#include "father.h"
#include <iostream>
using namespace std;
Child::Child():name("xiao Hua")
{
    //mama=new Mother;
    //baba=new Father;
}

void Child::answer(){
    cout<<endl<<name<<" is here!";
}

void Child::callParent()
{
    cout<<endl<<"I am calling my father!";
    cout<<endl<<"Father is not here!";
    //mama->answer();
    //baba->answer();
}
//mother.h
#ifndef MOTHER_H
#define MOTHER_H
#include <string>
using namespace std;
class Child;
class Mother
{
    Child *child;
    string name;
public:
    Mother();
    void callChild();
    void answer();
};

#endif // MOTHER_H
//mother.cpp
#include "mother.h"
#include "child.h"
#include <iostream>
using namespace std;
Mother::Mother():name("yyyyy")
{
    child=new Child;
}
void Mother::callChild(){
    cout<<endl<<"mama is calling my child!";
    child->answer();
}
void Mother::answer(){
    cout<<endl<<name<<" is here waiting for you!";
}
//father.h
#ifndef FATHER_H
#define FATHER_H

#include <string>
using namespace std;
class Child;
class Father
{
public:
    Father();
    string name;
    Child *child;
    void callChild();
    void answer();
};

#endif // FATHER_H
//father.cpp
#include "father.h"
#include "child.h"
#include <iostream>
using namespace std;
Father::Father():name("Lao Hua")
{
    child=new Child;
}

void Father::callChild(){
    cout<<endl<<"baba am calling my child!";
    child->answer();
}

void Father::answer(){
    cout<<endl<<name<<" is here waiting for you!";
}
//main.cpp
#include <QCoreApplication>
#include <iostream>
#include "father.h"
#include "child.h"
#include "mother.h"
using namespace std;
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    Child son;
    Father baba1;
    Mother mama1;
    son.callParent();
    baba1.callChild();
    mama1.callChild();
    cout<<endl;
    return a.exec();
}

 

以上是关于2000行之motherfatherchild的主要内容,如果未能解决你的问题,请参考以下文章

2000行之widget练习

2000行之widget练习之二

2000行之Qt简化写字板

2000行之Qt实现的简单登录界面

2000行之宏中#和##的区别

Game Maker Code 反其道而行之?