該代碼應該從 .h 檔案中獲取類,并在主檔案中使用它來創建一個自定義的寵物概要,以后可以將其存盤在另一個文本檔案中。我還沒有對文本檔案進行模塊化提取,因為我需要讓它至少作業并且能夠實際編譯和回傳構成自定義寵物概要的不同陣列。
/usr/bin/ld: /tmp/: in function `__static_initialization_and_destruction_0(int, int)':
program3.cpp:(.text 0x411): undefined reference to `dog_list::dog_list()'
/usr/bin/ld: program3.cpp:(.text 0x426): undefined reference to `dog_list::~dog_list()'
collect2: error: ld returned 1 exit status
我的 .h 檔案
#include<iostream>
#include<cstring>
#include<cctype>
#include<fstream>
using namespace std;
const int SIZE = 20;
const int END = 11;
class dog_list
{
public:
dog_list();
~dog_list();
void record_pets();
private:
char name[SIZE];
char breed[SIZE];
char species[SIZE];
char service[SIZE];
char special[SIZE];
};
dog_list op;
void record_pets();
我的主要 .cpp 檔案
#include "program3.h"
int main()
{
op.record_pets();
return 0;
}
void dog_list::record_pets()
{
char personal_list[SIZE];
int i = 0;
char again;
do
{
cout << "Enter in pets name: ";
cin.get(op.name,25,'\n');
cin.ignore(100,'\n');
cout << endl << "Enter breed of pet: ";
cin.get(op.breed, 25, '\n');
cin.ignore(100,'\n');
cout << endl << "Enter species: ";
cin.get(op.species,25,'\n');
cin.ignore(100,'\n');
cout << endl << "Enter in service qualifications: ";
cin.get(op.service,25,'\n');
cin.ignore(100,'\n');
cout << endl << "Enter in special notes: ";
cin.get(op.special,25,'\n');
cin.ignore(100,'\n');
cout << endl;
cout << "Name: " << op.name << endl;
cout <<"Breed: " << op.breed << endl;
cout << "Species: " << op.species << endl;
cout << "Service Qualifications: " << op.service << endl;
cout << "Special Notes: " << op.special << endl;
cout << "Pet saved! Would you like to enter another pet? Y/N: " << endl;
cin >> again;
cin.ignore(100,'\n');
cout << endl;
if(again == 'y')
{
again = toupper(again);
}
}while(again == 'Y' && i <= END);
{
i;
}
}
uj5u.com熱心網友回復:
你永遠不會實作建構式和解構式,你只是宣告它:
dog_list();
~dog_list();
例如,您必須在 main.cpp 中實作它:
dog_list::dog_list() = default;
dog_list::~dog_list() = default;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/357442.html
上一篇:在Python中顯示重復的結果
下一篇:陣列=復合資料型別=類?
