Why is this class abstract?

The compiler says the below class is abstract but I can't figure out why.

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

#include <Windows.h>
#include <gl/GL.h>

//#pragma comment(lib, "opengl32.lib")
//#pragma comment(lib, "glu32.lib")

// The action to be performed 
class action{

public: 

	// Virtuall destructor for abract class
	virtual ~action(){};

	// The operation to be performed
	virtual void operation()=0;

};

#endif action_h 


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

#include "action.h"

// Move forward and draw
class forward : public action
{
public:
	forward();
	~forward();

	// Operation move forward and draw
	void operation(int);
};

#endif foward_h 


1
2
3
4
5
6
7
8
9
10
11
12
13
#include "forward.h"

forward::forward(){
}

forward::~forward(){
}

// Operation move forward and draw
void forward::operation(int x){
	glColor3f( 1.0f, 1.0f, 1.0f ); 
	glVertex2f( 0.0f, 1.0f );
}
Last edited on
How is action declared?
where is ur action class. forward class is inheriting action class.
 
#endif foward_h  


u don't hv to write forware_h in here. endif is enough. plus it must be in upper case. But u wrote all in lawer case.
like this.....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef FORWARD_H
#define FORWARD_H

#include "action.h"

// Move forward and draw
class forward : public action
{
public:
	forward();
	~forward();

	// Operation move forward and draw
	void operation(int);
};

#endif   


plz put the correct action class code. Without that can't say anything.

Last edited on
From what I have read thus far in my programming book as soon as you do any function as:

virtual void someFunction(int param) = 0;

Then it is a pure virtual function which makes the class an abstract class. If you are trying to call someFunction with the base class it may give the error as pure virtual functions have no definitions in the base class. If you are calling that with an object that may be the problem. This is just a guess without seeing the whole code.

[EDIT]
Looking at the code, it is the full code. I'm not really seeing why the compiler is saying that because the way you do everything looks like how my book has its example (minus the OpenGL code).
Last edited on by closed account z6A9GNh0
void operation() and void operation(int) are entirely different functions. The first one is never implemented, so your class is abstract.
Last edited on
Topic archived. No new replies allowed.