Multiple class compile error

Saxtheowl

Still learning c++ and yet im stuck here, I got those classes:

Case.cpp:

#include "../inc_bomber/Case.hh"

Case::Case()
{

}

Case::~Case()
{

}

Case.hh:

#ifndef _CASE_HH_
# define _CASE_HH_

enum Type
  {
    FLOOR,
    WALL,
    BOMB,
    BLOCK,
    PLAYER1,
    PLAYER2,
    BOT,
    BONUS,
  };

class Case
{
private:

public:
  Case();
  virtual ~Case();

  virtual Type  getType() const = 0;
  virtual void  action() = 0;
  virtual int   getPos(int x, int y);
};

#endif /* CASE_HH_ */

I use those virtual on classes like this:

Player1.hh:

#ifndef _PLAYER1_HH_
# define _PLAYER1_HH_

#include "Case.hh"
#include "Map.hh"

class Player1 : public Case
{
private:
  int  x;
  int  y;

public:
  Player1();
  ~Player1();
  virtual Type getType() const;
  virtual void action();
  virtual void print_stuff();
  virtual int getPos(int x, int y);
};

#endif /* _PLAYER1_HH */

at the compile time I got this error, I guess im confusing the virtual usage but still dont find my mistake

g++ -Wall -Wextra -ansi -g3 -I includes/  -c src_bomber/Case.cpp -o src_bomber/Case.o
g++ -o bomber src_bomber/main.o src_bomber/GameMain.o src_bomber/Map.o src_bomber/Case.o src_bomber/Floor.o src_bomber/Block.o src_bomber/Wall.o src_bomber/Bomb.o src_bomber/Bot.o src_bomber/Player1.o src_bomber/Player2.o -Llibs/ -lgdl_gl -lGL -lGLEW -ldl -lrt -lfbxsdk -lSDL2 -lpthread -Wl,-rpath=./libs/
src_bomber/Case.o:(.rodata._ZTV4Case[vtable for Case]+0x30): undefined reference to `Case::getPos(int, int)'
collect2: ld returned 1 exit status
make: *** [bomber] Error 1
Mankarse

Case::getPos(int, int); is not marked as pure virtual (= 0), an so must have a supplied implementation (if you ever call getPos(int,int) on a reference to Case). You should add = 0 to the declaration of Case::getPos(int,int), as you did with all the other virtual member functions of Case, or you should add an implementation of Case::getPos(int,int), as you did with the constructor and destructor of Case.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error: [$compile:multidir] Multiple directives

For Each Compile Error (Multiple ranges)

C++ compile error: redefinition of 'class::class'

Babel compile error on static class properties

gradle generates protobuf class but shows compile error

Compile error when inheriting from class

Javassist ; Caused by: compile error: no such class: logger

compile error with implicit class method named "clone"

Error in makefile, compile multiple C files

Java multiple generic collection parameters compile error

Adding VBA for multiple checkboxes -returns a compile error

IntelliJ IDEA: Run single class ignoring compile error in other class

Compile error defining a std::hash for a template class nested class

Compile error after class declaration, Main doesn't "see" the class

Multiple definition error for a class function

Error handling of multiple class attributes

How to compile multiple class files in Java on LINUX shell?

Using std::conditional with is_class<int>, getting compile error

Class method and variable with same name, compile error in C++ not in Java?

Boost Spirit debug enum class (c++11) compile error

Typescript compile error when assigning class type to a generic variable

Instanceof does not show compile error with interface, but with abstract class does

C++ compile error when implementing template class

C++ class instance not initialized but no compile error, why

Accessing class instance method in unordered map causes compile error

Why does introducing std::mutex to member class generate this compile error?

Unexpected Cannot assign to property 'self' is immutable compile time error IN CLASS

Not throwing error in compile time when casting base to derived class

Custom exception class throws compile-time error