ClassName没有类型

时间:2014-02-16 23:21:42

标签: c++ header

我遇到了一个让我的程序编译的问题。这是我第一次使用代码分散在多个文件之间,这给了我一些问题。 我想我的主要问题是'CreditAccount'没有命名类型错误。

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;
}

我在这里很迷失,任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:2)

CreditAccount.h开头的行:

#ifdef  CREDIT_ACCOUNT_H

错了,应该是:

#ifndef  CREDIT_ACCOUNT_H

确保文件只包含一次(而不是永远不会包括在内)。