I'm currently learning C++, but It doesn't works like I expected. I made some classes for a BowlingGame (just something text-based) and that works well. But now I want to pass an object of a BowlingGame to another class, called ScoreCalculator.
The header file looks like:
#ifndef SCORECALCULATOR_H
#define SCORECALCULATOR_H
#include "BowlingGame.h"
class ScoreCalculator {
private:
BowlingGame * game;
public:
//constructor
ScoreCalculator(const BowlingGame &game);
//setters
void setGame(const BowlingGame &game);
};
#endif // SCORECALCULATOR_H
And the implementation looks like:
#include "ScoreCalculator.h"
#include "BowlingGame.h"
#include <iostream>
using namespace std;
ScoreCalculator::ScoreCalculator(const BowlingGame &game) {
setGame(game);
}
void ScoreCalculator::setGame(const BowlingGame &gamse) {
//* game = gamse; this fails
//cout << gamse.getLastFrameNummer(); this works
}
I would like to save the 'BowlingGame object' in the instance var game, but for some reason my console application crashes. I've no idea what I'm doing wrong. The failure is in the rule:
* game = gamse;
I looked up some examples on the internet, but can't find a solution.