简体   繁体   English

ClassName没有类型

[英]ClassName does not have a type

I've run into a slight issue getting my program to compile. 让我的程序编译时遇到了一个小问题。 This is the first time I've worked with code being spread out between multiple files and it's giving me some issues. 这是我第一次使用代码分散在多个文件之间,这给了我一些问题。 I suppose my main issue is the 'CreditAccount' does not name a type error. 我想我的主要问题是'CreditAccount'没有命名类型错误。

CreditAccount.h 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 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 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;
}

I'm pretty lost here, and any help would be greatly appreciated. 我很迷失在这里,任何帮助都将非常感激。

The line at the start of CreditAccount.h: CreditAccount.h开头的行:

#ifdef  CREDIT_ACCOUNT_H

is wrong, it should be: 是错的,它应该是:

#ifndef  CREDIT_ACCOUNT_H

to make sure that the file is only included once (instead of never getting included). 确保文件只包含一次(而不是永远不包括在内)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM