this is probably an include problem, i get these errors all over the code, and not only for string identifier for example error C2146: syntax error : missing ';' before identifier 'getName' and error C2146: syntax error : missing ';' before identifier 'name'
here’s an example class:
#include "stdafx.h"
class participant
{
public:
participant(int id, string name);
~participant(void);
int getId();
string getName();
private:
int id;
string name;
};
here’s my stdafx.h file:
#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;
So I compiled your code as-posted without your custom header files and it worked just fine. Based on that, I am going to wager that you have a problem in one of these header files:
It could be a macro, a class/struct not terminated with a semi-colon, etc. Check those out.
Lastly, a few of tangential issues:
First,
usinga namespace in a header file is a terrible idea. Any file that includes your header now hasusing namespace std;in it (this is bad). You probably don’t want to include that many header files in every file that includesstdafx.h.Secondly, once you remove that then
stringimmediately becomes undefined (use std::string instead).Last, why are your
#defines ended with semi-colons? No need for that.