Shahjahan Khokher
Shahjahan Khokher

Reputation: 33

error C4430: AND error C2143: syntax error : missing ';' before '*'

I am having these two errors.

error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

i already checked the solution from internet, every body recommend to #include <string> and using std::string instead of string, this is my header file. I applied the solutions but problem is still there. This is my code

friend std::ostream& operator<<(std::ostream& os, const Student& s);
friend class StudentList;

public:

    Student(int id = 0,std::string name = "none");
    virtual ~Student();
private:
    std::string name;
    int id;
    Student* next;  
RCourseList* rCList;

and this is my program's upper portion

#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <string>
#include "RCourseList.h"

This is RCourseList.h

#ifndef COURSELIST_H
#define RCOURSELIST_H

#include "RCourse.h"

class RCourseList

{
public:
    RCourseList();

private:
    RCourse* rhead;
};

#endif // RCOURSELIST_H'

Upvotes: 0

Views: 1338

Answers (1)

john
john

Reputation: 87944

Your header file RCourseList.h, has an error in its include guard

#ifndef COURSELIST_H
#define RCOURSELIST_H

it should be

#ifndef RCOURSELIST_H
#define RCOURSELIST_H

The reason this is a problem is because you have another header file called CourseList.h, that header also starts with an include guard.

#ifndef COURSELIST_H
#define COURSELIST_H

So CourseList.h defines the macro COURSELIST_H and this prevents the CourseList.h file from being included twice (in a single compilation) because #ifndef COURSELIST_His true on the first include but will be false on a second include.

But because your RCourseList.h wrongly starts with #ifndef COURSELIST_H including CourseList.h will also prevent a later RCourseList.h from being included.

In short, name your include guards after your header file names. Be very careful about this otherwise you get this kind of error.

Or you could replace the traditional include guard with the non-standard but widely supported #pragma once, like this

#pragma once

#include "RCourse.h"

class RCourseList

{
public:
    RCourseList();

private:
    RCourse* rhead;
};

#pragma once does exactly the same as the traditional include guard but without the possibility of this kind of error.

Upvotes: 1

Related Questions