Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error C2504 - Base class undefined

I have a rather simple problem

This is my firstcluster.h

#pragma once

#include "cluster.h"

class FirstCluster:public Cluster{
    ...

public:
    ...
};

Code for cluster.h:

#pragma once

// File: cluster.h

class Cluster {
protected:
    ...

public:
    ...
};

And i'm getting the error:

error C2504: 'Cluster' : base class undefined

Sometimes i get this IntelliSense error:

IntelliSense: incomplete type is not allowed ... Line 10 Column 27 

But it doesn't always come up.

The cluster.h is included, as you can see, and all other header files are protected with #pragma once

I really don't know what could go wrong here?

Can circular include make problems even if i protected everything with #pragma once? I'm using Visual Studio 2010.

like image 544
idjuradj Avatar asked Jan 29 '14 15:01

idjuradj


2 Answers

I got this due to circular include.

I included all my headers in "include.h" and include it in everywhere else.

I managed to avoid circular include by just including standard headers in include.h.

like image 72
user3946110 Avatar answered Sep 30 '22 17:09

user3946110


I've had the exact same problem, adding

#ifndef CLUSTER_H
#define CLUSTER_H

/* your code */

#endif

helped to solve the problem. the ifndef part is obviously for include duplications but "define", i think, did help.

like image 42
sleepyhead Avatar answered Sep 30 '22 18:09

sleepyhead