x is not a class or namespace name

I have two classes Plugin and Display and Display inherits from Plugin. Plugin can't call a static Display method, how can I solve this? The Display class works fine elsewhere, and this all works fine with the line commented out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef PLUGIN_H
#define PLUGIN_H

#include "Display.h"
#include "Data.h"

class Plugin
{
public:
	typedef void (*ptrToFunction)();
	virtual ptrToFunction getRenderPointer() = 0;
	virtual void editData(Data* data) = 0;

	void drawGraph()
	{
		Display::renderPointsGraph(); // This is the problem line
	}	
};

#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef DISPLAY_H
#define DISPLAY_H

#include <stdlib.h>
#include <stdio.h>
#include <gl/glew.h>
#include <gl/glut.h>
#include <vector>;
#include <iostream>
#include <vector>
#include <sstream>
#include <string>

#include "Plugin.h"
#include "Data.h"
#include "GlutUI.h"

#define BUFFER_OFFSET(i) ((char*)NULL +(i))

class Display : public Plugin
{
private:
	const static float speed;
public:	
	static Data* data;
	static std::vector<GLuint>* bufferIDs;
	static float xRot, yRot;

	static void renderPointsGraph();
	static void drawMouseCoords();
	static void drawGraph();
	static void drawPoints();
	static void rotate(std::string axis, bool forwards);

	typedef void (*ptrToFunction)();
	ptrToFunction getRenderPointer()
	{
		return &(Display::renderPointsGraph);
	}
	void editData(Data* data) {}
};

#endif 


I can paste more code if necessary.

Thanks for any help!

Last edited on
You have an interdepencendy problem. Plugin.h is including Display.h and Display.h is including Plugin.h. That is problematic.

See section 4 and up: http://www.cplusplus.com/forum/articles/10627/#msg49679

To solve this, Plugin.h must not include Display.h until after the Plugin class is fully defined.

Here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef PLUGIN_H
#define PLUGIN_H

//#include "Display.h"  // don't include this here
#include "Data.h"

class Plugin
{
public:
	typedef void (*ptrToFunction)();
	virtual ptrToFunction getRenderPointer() = 0;
	virtual void editData(Data* data) = 0;

	void drawGraph();
//	{  // don't inline this here
//		Display::renderPointsGraph();
//	}
};

/*

  Now that Plugin is fully defined, it is OK to include Display.h

*/

#include "Display.h"

inline void Plugin::drawGraph()  // now we can inline this
{
	Display::renderPointsGraph();
}

#endif  
Thanks for the reply. I tried your plugin fix but I am still getting the same errors. "'Display': is not a class or namespace name". "'renderPointsGraph': identifier not found".
Does Data.h include any of these headers? If so, it probably shouldn't.

You can't just have all your headers include each other. Careless including leads to trouble.

Really -- read section 4 here: http://www.cplusplus.com/forum/articles/10627/#msg49679

(EDIT: Section 7 is also on point)

It explains these problems and gives easy to follow guidelines as to how to avoid them.

Last edited on
No Data.h doesn't include any of them. It is included in another .cpp file, but that's so I can access one of Display's static functions. How else am I supposed to do that without including the header in the file?
Data.h must include it -- or maybe it includes something else that includes it. That's the only way I can make sense of the error.

In any event, upon further inspection, you don't need to include data.h at all:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef PLUGIN_H
#define PLUGIN_H

//#include "Data.h"  // don't do this

class Data;  // do this instead

class Plugin
{
public:
	typedef void (*ptrToFunction)();
	virtual ptrToFunction getRenderPointer() = 0;
	virtual void editData(Data* data) = 0;

	void drawGraph();
};

//==============================

#include "Display.h"

inline void Plugin::drawGraph()
{
	Display::renderPointsGraph();
}

#endif   
Ok now even without including data I have the same errors. This is frustrating.
Bump, any ideas anyone?
hello soupsoup,

well using names like Display, Plugin, and Data without surrounding/protecting namespaces are generally no good idea since it could be defined elsewhere.

if a line like #define Display whatever exists you're lost.


I'd suggest that you rename your Display to don't know maybe xxxxDisplay (all other accordingly) and see what happens
Last edited on
Thanks for the reply coder, I tried to replace Display with GLDisplay, but no luck, any other ideas?
Sorry to bump again but I really can't figure this out.

Edit: I moved the definition of drawGraph() into a seperate Plugin.cpp file and moved a few includes, and now it works!
Last edited on
Topic archived. No new replies allowed.