Error "no matching function for call to" C++

I have been looking around here on stack and references to try to figure this out but after a couple days I am stumped. The program is a simple basketball stats keeper, allowing one to enter in the stats from a basketball game, and then sort and display the stats. I looked around for quite a while but most people were having an issue with this error because they were using base classes (square -> rectangle), which isn't my issue. I'm not very familiar with c++, so I have tried a series of things to get this to work including variations of

[]switching the function parameters from std::vector&, ..*, .. &example, etc.. []playing around with how I was constructing the menu classes constructor, omiting it completely.

If somebody can give me some insight into what I'm missing here it would be greatly appreciated!

Fair note: This is for school.

In main.cpp:

#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include "player.hpp"
#include "stats.hpp"
#include "menu.hpp"

int main(int argc, char *argv[]){

Menu menu;
char inputType;
std::vector<Player> gameStats;
inputType = menu.displayWelcomeMenu();
while(inputType!= 'd' || inputType!= 'k'){
    std::cout << "oops, wrong input!" << std::endl;
    menu.displayWelcomeMenu();
    }
if(inputType='d'){
    std::ifstream fileStream("input.txt");
    Stats::initializeVectorFromFile(&gameStats, &fileStream);
}
else{
    Stats::initializeVectorFromUser(&gameStats);
}
menu.displayMainMenu(&gameStats);

return 0;
}

In menu.cpp:

#include "player.hpp"
#include "stats.hpp"
#include "menu.hpp"
#include <string>
#include <vector>
#include <iostream>

Menu::Menu(){}
//functions with matching parameters to menu.hpp.......

In menu.hpp:

#ifndef MENU_HPP_
#define MENU_HPP_

#include "player.hpp"
#include "stats.hpp"
#include <string>
#include <vector>
#include <iostream>

class Menu{
public:
    Menu();
    void handleMenuFlow(std::string, char, std::vector<Player> &);
    char displayWelcomeMenu();
    void displayMainMenu(std::vector<Player> &);
    void displaySortMenu(std::vector<Player> &);
    void displayAvailOptionMenu(std::vector<Player> &);
    char displaySortOptionMenu();
    void displayVectorByName(std::vector<Player> &);
    void displayVectorByInt(std::vector<Player> &, char);
    void displayStats(std::vector<Player> &);
    void displayDoubles(std::vector<Player> &);
    int exitProgram();
};
#endif

and the error reads:

g++ -c -g -std=c++0x main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:26:33: error: no matching function for call to     
‘Menu::displayMainMenu(std::vector<Player>*)’
  menu.displayMainMenu(&gameStats);
                                 ^
main.cpp:26:33: note: candidate is:
    In file included from main.cpp:7:0:
menu.hpp:15:7: note: void Menu::displayMainMenu(std::vector<Player>&)
  void displayMainMenu(std::vector<Player> &);
       ^
menu.hpp:15:7: note:   no known conversion for argument 1 from ‘std::vector<Player>*’ 
to ‘std::vector<Player>&’
make: *** [main.o] Error 1

Answers


Your functions in the menu class take a reference (&), but you pass a memory address, commonly associated with a pointer (*), you can fix this by omitting the & from function calls. Example:

From:

menu.displayMainMenu(&gameStats);

To:

menu.displayMainMenu(gameStats);

Take all the & operators out of main.cpp. This operator means to create a pointer to the operand. However your functions are not expecting a pointer; they expect to bind a reference to the object itself.

The error message says this: it cannot convert your pointer to a reference.


Need Your Help

Storing passwords used by a Windows (NT) service

mysql windows service passwords credentials

on a Windows local network I have a MySql database, several client applications (that only query the database) and one Windows NT service that fills the database on a regular basis.

syncdb error in django when trying to run python manage.py syncdb

python django django-models django-syncdb syncdb

Im Following a django tutorial but I triple checked everything and its no working for me this is what I get.... what did I do wrong.