I'm about to submit my program for my course, but there must be at least 2 virtual functions in it, and whenever there's a virtual function, I get a runtime error.
//Jatek.h
#ifndef JATEK_H
#define JATEK_H
#include <iostream>
usingnamespace std;
class Jatek {
protected:
char* leiras;
public:
Jatek();
//rest of the code
};
//Jatek.cpp
#include "Jatek.h"
Jatek::Jatek() {
leiras = "nincs leiras";
}
//rest of the code
//Tablajatek.h
#ifndef TABLAJATEK_H
#define TABLAJATEK_H
#include "Jatek.h"
#include <iostream>
usingnamespace std;
class Tablajatek: public Jatek {
protected:
int n;
int** tabla;
public:
Tablajatek();
virtualvoid a();
//rest of the code
};
//Tablajatek.cpp
#include "Tablajatek.h"
Tablajatek::Tablajatek(): Jatek() {
n = 8;
tabla = newint*[n];
for (int i = 0; i<n; i++) {
tabla[i] = newint[n];
}
for (int i = 0; i<n; i++) {
for (int j = 0; j<n; j++) {
tabla[i][j] = 0;
}
}
}
void Tablajatek::a() {
cout<<"hi";
}
//rest of the code
//Reversi.h
#ifndef OSZTALY_H
#define OSZTALY_H
#include <iostream>
#include "Tablajatek.h"
usingnamespace std;
class Reversi: public Tablajatek {
private:
int szabad; //szabad mezők száma
int kovetkezo;
public:
Reversi();
//rest of the code
};
//Reversi.cpp
#include "Reversi.h"
Reversi::Reversi() : Tablajatek() {
kovetkezo = 1;
szabad = 62; //8*8-4 = 62
tabla[3][3] = 1;
tabla[4][4] = 1;
tabla[3][4] = 2;
tabla[4][3] = 2;
//rest of the code
}
//main.cpp
#include <fstream>
#include "Jatek.h"
#include "Tablajatek.h"
#include "Reversi.h"
int main() {
Reversi Reverzi;
//rest of the code...
}
I tried putting in any kind of virtual function in any of the classes and it crashed at the "Reversi Reverzi;" part. Without a virtual function, it works fine.
PS: I tried putting it in without separating: like virtualvoid a() {cout<<"hi";}
and it works, but we have to separate the code...
Any help is appreciated