不同文件上的类,如何使其工作?

时间:2018-05-07 19:57:38

标签: c++

我的问题是如何将类放在不同的文件中并使程序正常工作?当我尝试在Student.h文件中构建并运行它时,我收到错误---> string没有命名类型

main.cpp:

<192.168.56.52> ESTABLISH SSH CONNECTION FOR USER: ubuntu
<192.168.56.52> SSH: EXEC ssh -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o IdentityFile=/home/gil/vagrant/vm/.vagrant/machines/onno/virtualbox/private_key -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=22 -o 'IdentityFile="/home/gil/vagrant/vm/.vagrant/machines/onno/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=30 -o ControlPath=/home/gil/.ansible/cp/7ecc584fc8 -tt 192.168.56.52 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-ujsujrqhjylrxjabjmxzblqijoesfdib; sudo apt-get -y install python-simplejson'"'"''
<192.168.56.52> (255, '', "Warning: Permanently added '192.168.56.52' (ECDSA) to the list of known hosts.\r\nPermission denied (publickey).\r\n")

Student.h:

#include <iostream>
#include "Student.h"

using namespace std;

int main()
{
    Student *a;

    a = new Student(1,"Astudent");
    a->printStudent();

    system("PAUSE");
    return 0;
}

Student.cpp:

#ifndef STUDENT_H
#define STUDENT_H

class Student
{
    private:
        int id;
        string name;

    public:
        Student(int id,string name);
        void printStudent();
};

#endif

1 个答案:

答案 0 :(得分:1)

Student.h需要包含字符串才能使用string作为类型。 e.g:

#include <string>