Mic*_*ael 2 c++ visual-studio-2010
这可能是一个包含问题,我在代码中得到了这些错误,而不仅仅是字符串标识符,例如error C2146: syntax error : missing ';' before identifier 'getName'和error C2146: syntax error : missing ';' before identifier 'name'
这是一个示例类:
#include "stdafx.h"
class participant
{
public:
participant(int id, string name);
~participant(void);
int getId();
string getName();
private:
int id;
string name;
};
Run Code Online (Sandbox Code Playgroud)
这是我的stdafx.h档案:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include "day.h"
#include "appointment.h"
#include "extendedAppointment.h"
#include "participant.h"
#include "calendar.h"
using namespace std;
#define no_such_appointment_error 20;
#define conflicting_appointments_error 21;
#define noSuchDayError 22;
#define incorrectAppointmentError 23;
Run Code Online (Sandbox Code Playgroud)
所以我编译你的代码as-posted没有你的自定义头文件,它工作得很好.基于此,我打算你在其中一个头文件中遇到问题:
#include "day.h"
#include "appointment.h"
#include "extendedAppointment.h"
#include "participant.h"
#include "calendar.h"
Run Code Online (Sandbox Code Playgroud)
它可能是一个宏,一个没有以分号结尾的类/结构,等等.检查出来.
最后,一些切线问题:
首先,using头文件中的命名空间是一个糟糕的主意.现在包含您的标题的任何文件都包含using namespace std;在其中(这很糟糕).您可能不希望在包含的每个文件中包含那么多头文件stdafx.h.
其次,一旦删除它然后string立即变为未定义(使用std :: string代替).
最后,你为什么#define用分号结束?没必要.