对象指针不起作用

时间:2016-08-16 01:35:09

标签: c++ function class pointers

我的任务是在类中创建一个对象,初始化它并输出(使用指向类的指针)。此代码编译完美,但输出不会出现。我真的很感激任何帮助,谢谢你提前!

#include <iostream>
#include <string>

using namespace std;

class family
{
public:
    void setWife(string w)
    {w = wife;};
    string getWife()
    {return wife;};
    void setHusband(string h)
    {husband = h;};
    string getHusband()
    {return husband;};
    void setSon(string s)
    {s  = son;};
    string getSon()
    {return son;};
    void setDaughter1(string d1)
    {d1  = daughter1;};
    string getDaughter1()
    {return daughter1;};
    void setDaughter2(string d2)
    {daughter2 = d2;};
    string getDaughter2()
    {return daughter2;};
    double* getPointer()
    {return &pointer;};
    void initialize()
    {
        setWife("Shirley Collin");
        setHusband("Donald Collin");
        setSon("Collin Collin");
        setDaughter1("Harriet Collin");
        setDaughter2("Hillary Collin");
    }
    friend void output(family* Collin);


private:
    string wife;
    string husband;
    string son;
    string daughter1;
    string daughter2;
    double pointer;
};


void output(family* Collin)
{cout << "Husband is " <<Collin->getHusband()<< endl;
    cout << "wife is " << Collin ->getWife() << endl;
    cout << "son is " << Collin->getSon() << endl;
    cout << "daughter1 is " << Collin->getDaughter1() << endl;
    cout << "daughter2 is " <<  Collin->getDaughter2()<< endl;
};

int main()
{family Collin;
    Collin.initialize();
    family *pointer = new family;
    output (pointer);
    cin.ignore();

}

0 个答案:

没有答案