我讨厌在这样一个常见的错误上寻求帮助,但我一直在盯着我的代码两个小时,试图找到编译器所说的缺少的分号和未指定的类型:
错误C2146:语法错误:缺少';'在标识符'历史'之前.....:
错误C4430: 缺少类型说明符 - 假设为int。注意:C ++不支持 default-int 1> c:\ users \ alex \ dropbox \ lab4 \ lab4 \ lab4 \ customer.h(49): 错误C4430:缺少类型说明符 - 假定为int。注意:C ++没有 支持default-int
#pragma once
#include <string>
using std::string;
#include "customerdata.h"
#include "rentalhistory.h"
#include "item.h"
#include "customer.h"
/*---------------------------------------------------------------------------
Purpose: class Customer contains methods to grab information about a customer,
such as their id number, address, phone number (stored in class CustomerData).
It also contains methods that will allow access to information about a
customer’s rental history (stored in class RentalHistory).
CONSTRUCTION:
(1) empty construction. (2) name and id (3) with information provided by
CustomerData object.
--------------------------------------------------------------------------- */
class Customer
{
public:
Customer();
Customer( const Customer & );
Customer( string, string, int );
Customer( const CustomerData & );
~Customer();
// get customer's first name.
string getFirstName() const;
// get customer's last name.
string getLastName() const;
// get customer's id number
int getIdNum() const;
// add a movie to customer's rental history
void addMovie( Item *&, string code );
// checks to see if it is a valid customer
bool isValidCustomer();
// prints the customer's rental history
void printHistory() const;
Customer & operator=( Customer &rhs );
private:
CustomerData data; // object that contains customer's information
RentalHistory history; // object that contains customer's rental history
};
答案 0 :(得分:5)
错误消息表明编译器无法将RentalHistory
识别为类型。如果在包含的rentalhistory.h
中正确定义了类型,则此类问题的最常见原因将是循环依赖。
rentalhistory.h
是否尝试加入customer.h
?在这种情况下,您需要解决循环包含问题。在rentalhistory.h
中,您很可能必须添加class Customer;
之类的前瞻性声明,而不是包含customer.h
。
另外:为什么customer.h
试图包含自己?