私が間違っていることがわからない、誰かが正しい方向に私を向けることを望んでいた。顧客クラスを作成しましたが、初期化できません。C++でオブジェクトを初期化する際に問題がある - Linux
customer.h
#ifndef CUSTOMER_H
#define CUSTOMER_H
#include "defs.h"
#include <string>
using namespace std;
class Customer
{
public:
Customer(string fName, string lName);
string getFirstName();
string getLastName();
int getCustID();
int getNumAccounts();
protected:
string firstName;
string lastName;
int custID;
int numAccounts;
};
#endif
customer.cc
#include "defs.h"
#include "Customer.h"
int Customer::nextCustID = 9001;
void Customer(){
//nothing;
}
void Customer::Customer(int test, int tes2)
{
custID = 100;
firstName = "George";
lastName = "sadfsad";
numAccounts = 0;
}
void Customer::Customer(string fName, string lName)
{
custID = nextCustID++;
string firstName = fName;
string lastName = lName;
numAccounts = 0;
}
int Customer::getCustID() { return custID; }
string Customer::getFirstName() { return firstName; }
string Customer::getLastName() { return lastName; }
int Customer::getNumAccounts() { return custID; }
私は
Customer test("Billy", "Bob");
で顧客を初期化しようとしています。しかし、私は初期化しようとすると、私はエラーを取得します
BankControl.cc:(.text+0xaf): undefined reference to `Customer::Customer(std::string, std::string)'
collect2: error: ld returned 1 exit status
誰かが何らかの入力をしていると、私が間違っていることを理解できません。ありがとうございます。
Bankcontrol.cc
#include "BankControl.h"
#include "Account.h"
#include "Customer.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include "View.h"
BankControl::BankControl()
{
Customer test("Joe", "Billy");
}
"defs.h"から何を使用していますか? –
エラーメッセージはbankcontrol.ccにエラーが発生したと言います - このコードを質問に追加してください – EkcenierK
*間違っていませんが、ヘッダーファイルで 'namespace std'を使用しないことをお勧めします。 –