現在、ユーザーから継承する抽象 User クラスと Student クラスがあります。main から Student クラスのインスタンスを初期化しようとしています。このエラーが表示されます
アーキテクチャ i386 の未定義シンボル: "Student::Student()"、参照元: ccJo7npg.o の _main "Student::~Student()"、参照元: ccJo7npg.o の _main ld: シンボルが見つかりませんアーキテクチャ i386 collect2: ld が 1 つの終了ステータスを返しました
ユーザー クラス:
#include <iostream>
#import <stdio.h>
#import <string.h>
using namespace std;
class User
{
public:
void setName(const string n)
{
name = n;
}
string getName()
{
return name;
}
void setUsername(const string u)
{
username = u;
}
string getUsername()
{
return username;
}
void setPassword(const string p)
{
password = p;
}
string getPassword()
{
return password;
}
void setID(const int ID)
{
this->ID=ID;
}
int getID()
{
return ID;
}
void setClassID(const int cid)
{
classID=cid;
}
int getClassID()
{
return classID;
}
void logOut()
{
cout<<"you have logged out"<<endl;
}
void print()
{
cout<< "Student : "<< ID << name << " "<< username << " " << password << endl;
}
virtual void menu()=0;
protected:
int classID, ID;
string name, username, password;
};
学生クラス:
#include <iostream>
#include "User.h"
using namespace std;
class Student: public User
{
public:
Student()
{
classID=0;
ID=0;
username="";
name="";
password="";
}
~Student()
{
cout<<"destructor"<<endl;
}
void studyDeck(const int i)
{
}
void viewScores(const int)
{
}
void viewScores()
{
}
virtual void menu()
{
cout << "Student menu" << endl;
}
};
Main.cpp:
#include <iostream>
#include "User.h"
#include "Student.h"
using namespace std;
int main()
{
Student s;
return 0;
}
「 g++ User.cpp Student.cpp main.cpp 」で g++ でコンパイルしています。
ありがとう!