0

This is the exact error code:

LNK2019 unresolved external symbol "public: __thiscall guessingGame::guessingGame(void)" (??0guessingGame@@QAE@XZ) referenced in function _main

I am not sure what is going on. When I tried changing the arguments, the error went away but then I got too few arguments and when I tried making sure all of the symbols matched it still gave me the error. I have no idea what to do.

Driver.cpp

#include "pch.h"
#include <iostream>
#include "Game.h"


using namespace std;



int main()
{
    int howManyNumbers = 0, range = 0;
    cout << "Enter the Number of Integers (n): ";
    cin >> howManyNumbers;
    cout << "Enter the Number of Each Integer from 1 to (m): ";
    cin >> range;
    guessingGame start;
    start.createRandomNumbers(howManyNumbers, range);
    

}

Game.h

#ifndef Game
#define Game
#include "pch.h"
#include <stdlib.h>
#include <iostream>

using namespace std;

class guessingGame {
    int numberRight = 0;
    int numberGuessed;
    int numbers[];

public:
    guessingGame();

    void createRandomNumbers(int n, int m);


};

Game.cpp

#include "pch.h"
#include "Game.h"



void guessingGame::createRandomNumbers(int n, int m) {

    for (int i = 0; i < n; i++) {
        numbers[i] = 1 + rand() % m;
    }
    
    while (numberRight < n) {
        cout << "Enter your guesses for the " << n << " integers in the range from 1 to " << m << " that have been selected: ";
        cin >> numberGuessed;
        for (int i = 0; i < n; i++) {
            if (numberGuessed = numbers[i]) {
                numberRight++;
                cout << numberRight << " of your gusses are correct. Guess again.";
            }
        }
    }

}
JaMiT
  • 14,422
  • 4
  • 15
  • 31
Yuuya
  • 1
  • 2
    As the error message says, you declare a default constructor but never implement it. – tkausl May 31 '21 at 02:43
  • You declared you were providing the default ctor when you claimed `guessingGame();`. So... where is it? I see an implementation of `guessingGame::createRandomNumbers`. I see no implementation of `guessingGame::guessingGame` – WhozCraig May 31 '21 at 02:44
  • "*I have no idea what to do."* -- one useful trick is to argue with your compiler. Write out your case for why the compiler is wrong. This is similar to [rubber duck debugging](https://en.wikipedia.org/wiki/Rubber_duck_debugging). In your particular situation, the compiler said that `guessingGame::guessingGame(void)` is unresolved; can you point to the place in your code where your compiler is supposed to find this definition? (Note: definition, not merely declaration.) Build your case around that. – JaMiT May 31 '21 at 02:52
  • 2
    You made a promise to the compiler that there exists the constructor for `guessingGame()`. The compiler accepted your promise and compiled your code with no errors. Now the program that is responsible for putting together the final program, the **linker** (note that the error identifier starts with **LNK**), comes in and says, "ok, I'm now putting together the program, you are making this call to the constructor, but I can't find this function anywhere". That's the error you're seeing. – PaulMcKenzie May 31 '21 at 03:29

0 Answers0