2014-02-16 35 views
0

我遇到了讓我的程序編譯的一個小問題。這是我第一次使用在多個文件之間傳播的代碼,它給了我一些問題。 我想我的主要問題是'CreditAccount'沒有命名類型錯誤。ClassName沒有類型

CreditAccount.h

#ifdef CREDIT_ACCOUNT_H 
#define CREDIT_ACCOUNT_H 
class CreditAccount 
{ 
    private: 
     char accountNum[20]; 
     char custName[21]; 
     double credLimit; 
     double accountBal; 

    public; 
     CreditAccount(); 
     CreditAccount(char[], char[], double, double); 
}; 

#endif 

CreditAccount.cpp

#include "CreditAccount.h" 
#include <cstring> 
CreditAccount::CreditAccount() 
{ 
accountNum[0] = '\0'; 
custName[0] = '\0'; 
credLimit = 0; 
accountBal = 0; 
} 

CreditAccount::CreditAccount(char newAccountNum[], char newCustName[], double newCredLimit, double newAccountBal) 
{ 
newAccountNum = strcpy(newAccountNum, accountNum); 
newCustName = strcpy(newCustName, custName); 
newCredLimit = credLimit; 
newAccountBal = accountBal; 
} 

assign2.cpp

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

using std::cout; 
using std::endl; 

int main() 
{ 
char code1[20] = "1111-1111-1111-1111"; 
char name1[21] = "Jermaine Arnold"; 
char code2[20] = "2222-2222-2222-2222"; 
char name2[21] = "Vanessa Long"; 

// Test default constructor 
CreditAccount account1; 
return 0; 
} 

我幾乎失去了這裏,和任何幫助將不勝感激。

+3

'public;'應該是'public:'在'CreditAccount.h'中。 –

+0

爲什麼不使用'std :: string'? –

+0

對不起公開;這是我之前注意到的,忘記了改變。 – Khemp

回答

2

在CreditAccount.h開始行:

#ifdef CREDIT_ACCOUNT_H 

是錯誤的,它應該是:

#ifndef CREDIT_ACCOUNT_H 

,以確保該文件只包含一次(而不是從未得到包括在內)。