我讨厌在这样一个常见错误上寻求帮助,但我一直在盯着我的代码两个小时,试图找到编译器所说的缺少的分号和未指定的类型:
错误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
};
Run Code Online (Sandbox Code Playgroud)
该错误消息表明编译器无法识别RentalHistory为类型.如果在包含的内容中正确定义了类型rentalhistory.h,则此类问题的最常见原因将是循环依赖性.
是否rentalhistory.h尝试加入customer.h?在这种情况下,您需要解决循环包含问题.在rentalhistory.h你最有可能添加一个正向的声明一样class Customer;,而不是包括的customer.h.
另外:为什么要customer.h尝试包括自己?