Error C2660 'menu': function does not take 5 arguments

I am developing a text based RPG game, and to make things quicker, I created a function to make a menu for the player to choose from, each option will result in a different consequence. When I tried putting in place holders for text just to test the funtion, I got the error: 'menu': function does not take 5 arguments

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  int main() {
	Character player;
	cout << "Hello";
	menu("Choose an action", 10, "action 1", "action 2", "action 3");
	if (action == 1) {
		cout << "1";
		Console::ReadKey();
	}
	else if (action == 2) {
		cout << "2";
		Console::ReadKey();
	}
	else {
		cout << "3";
		Console::ReadKey();
	}
}

int menu(string scenerio, int health, string option_1, string option_2, string option_3) {
	int action = 1;
	bool action_chosen = false;
	
	system("CLS");
	cout << scenerio << "\n\n" << health << "\n\n";

	while (action_chosen == false) {
		if (_getch() == 72) {
			if (action < 3) {
				action++;
			}
		}

		if (_getch() == 80) {
			if (action > 1) {
				action--;
			}
		}

		if (_getch() == 13) {
			action_chosen = true;
		}
                //This part here is strictly for cosmetics. It makes the user
                //select an option with arrow keys.
		switch (action) {
		case 1:
			cout << "--> [" + option_1 + "] <--";
			cout << "     " + option_2 + "     ";
			cout << "     " + option_3 + "     ";
		case 2:
			cout << "     " + option_1 + "     ";
			cout << "--> [" + option_2 + "] <--";
			cout << "     " + option_3 + "     ";
		case 3:
			cout << "     " + option_1 + "     ";
			cout << "     " + option_2 + "     ";
			cout << "--> [" + option_3 + "] <--";
		}
	}
	return action;
}.


Any help would be greatly appriciated! Thanks!
Hi,
Could you please let us see the function menu()'s prototype?

Could you please let us see the function menu()'s prototype?


Sure! In the displayed code, there are two shown functions. The first one is the main loop, where I try to execute menu(). The second is the menu funtion, it is an int function, and it takes in 5 arguments. 2 strings, and 3 integers. It returns the "action" variable, which is an integer. I hope that helps. :)
> I hope that helps. :)
:]

So can you let us see your full code?
Maybe you also show us the header as well.
closed account (E0p9LyTq)
The code you showed doesn't include the function's prototype, just the implementation.

A function prototype:
float distance(float, float); // don't need to include parameter(s), just the type(s)

If you put your menu() function before main() no prototype is needed, the compiler knows what the function's parameters are before the first use.
This is all of my code, it is the source code. (named Source.cpp)I have no other headers. If it matters, I am using Visual Studio Community 2015.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//Game played via text

#include <iostream>
#include <string>
#include <sstream>
#include <conio.h>
#include <cmath>

using namespace std;
using namespace System;

int action;

class Character {
public:
	//stats for player
	int health = 10;
	int magic;
	int strength;
	int stealth;
	int charisma;
	int dexterity;
	string name;
	bool has_map = false;
};

int menu();

int main() {
	Character player;
	cout << "Hello";
	menu("Choose an action", 10, "action 1", "action 2", "action 3");
	if (action == 1) {
		cout << "1";
		Console::ReadKey();
	}
	else if (action == 2) {
		cout << "2";
		Console::ReadKey();
	}
	else {
		cout << "3";
		Console::ReadKey();
	}
}

int menu(string scenerio, int health, string option_1, string option_2, string option_3) {
	int action = 1;
	bool action_chosen = false;
	
	system("CLS");
	cout << scenerio << "\n\n" << health << "\n\n";

	while (action_chosen == false) {
		if (_getch() == 72) {
			if (action < 3) {
				action++;
			}
		}

		if (_getch() == 80) {
			if (action > 1) {
				action--;
			}
		}

		if (_getch() == 13) {
			action_chosen = true;
		}

		switch (action) {
		case 1:
			cout << "--> [" + option_1 + "] <--";
			cout << "     " + option_2 + "     ";
			cout << "     " + option_3 + "     ";
		case 2:
			cout << "     " + option_1 + "     ";
			cout << "--> [" + option_2 + "] <--";
			cout << "     " + option_3 + "     ";
		case 3:
			cout << "     " + option_1 + "     ";
			cout << "     " + option_2 + "     ";
			cout << "--> [" + option_3 + "] <--";
		}
	}
	return action;
}
> In the displayed code, there are two shown functions. The first one is the main loop, where I try to execute menu(). The second is the menu function, it is an int function, and it takes in 5 arguments. 2 strings, and 3 integers. It returns the "action" variable, which is an integer...

What you said is "function definition".
What I need is "function declaration".
Last edited on
closed account (E0p9LyTq)
Line 27: int menu(); doesn't match what you wrote in line 47.

Line 27 should be something like:
int menu(string scenerio, int health, string option_1, string option_2, string option_3);
or
int menu(string, int, string, string, string);
Last edited on
Alright, I added the declaration and the error has gone away, but there is another problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//Game played via text

#include <iostream>
#include <string>
#include <sstream>
#include <conio.h>
#include <cmath>

using namespace std;
using namespace System;

int action;

class Character {
public:
	//stats for player
	int health = 10;
	int magic;
	int strength;
	int stealth;
	int charisma;
	int dexterity;
	string name;
	bool has_map = false;
};

int menu(string, int, string, string, string);

int main() {
	Character player;
	cout << "Hello";
	menu("Choose an action", 10, "action 1", "action 2", "action 3");
	if (action == 1) {
		cout << "1";
		Console::ReadKey();
	}
	else if (action == 2) {
		cout << "2";
		Console::ReadKey();
	}
	else {
		cout << "3";
		Console::ReadKey();
	}
}

int menu(string scenerio, int health, string option_1, string option_2, string option_3) {
	int action = 1;
	bool action_chosen = false;
	
	system("CLS");
	cout << scenerio << "\n\n" << health << "\n\n";

	while (action_chosen == false) {
		if (_getch() == 72) {
			if (action < 3) {
				action++;
			}
		}

		if (_getch() == 80) {
			if (action > 1) {
				action--;
			}
		}

		if (_getch() == 13) {
			action_chosen = true;
		}
		system("CLS");
		switch (action) {
		case 1:
			cout << "--> [" + option_1 + "] <--";
			cout << "     " + option_2 + "     ";
			cout << "     " + option_3 + "     ";
		case 2:
			cout << "     " + option_1 + "     ";
			cout << "--> [" + option_2 + "] <--";
			cout << "     " + option_3 + "     ";
		case 3:
			cout << "     " + option_1 + "     ";
			cout << "     " + option_2 + "     ";
			cout << "--> [" + option_3 + "] <--";
		}
	}
	return action;
}


The other problem is that when it displays the menu, is displays it in an exetremly sloppy way, and it does not respond correctly to the arrow key inputs.

closed account (E0p9LyTq)
Using arrow keys for input is a GUI thing, not a C++ issue.
Sylvagon,

This isn't a direct response to your question. However I too wanted to make a text-based RPG in the console a while ago, and I too wanted a nice menu system.

I don't expect you to understand this right away, but it worked for me very well. I ended up programming the game in a "menu driven" paradigm.

Big thanks to JLBorges and the rest who helped me with this when I was stuck, I don't forget.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
typedef std::function<void(void)> MenuHandle;

template<typename... ARGS>
inline MenuHandle MakeHandle(ARGS&&... args) { return std::bind((args)...); }

class MenuItem
{
private:
    int key;
    std::string name;
    std::function<void(void)> handle;
public:
    MenuItem() {}
    MenuItem(const int& k, const std::string& n, const std::function<void(void)>& h)
    : key(k), name(n), handle(h) {}
    void Call() { handle(); }
    const int& GetKey() { return key; }
    const std::string& GetName() { return name; }
};

class Menu
{
private:
    std::string menu_name;
    std::vector<MenuItem> menu_container;
public:
    Menu(const std::string& name, std::vector<std::string> desc, std::vector<std::function<void(void)>> handles): menu_name(name)
    {
        if(desc.size() != handles.size()) throw std::runtime_error("Menu: Constructor arguments not equal");
        for(size_t i = 0; i < desc.size(); i++)
            menu_container.push_back(MenuItem(i+1,desc[i],handles[i]));
    }
    void Show()
    {
        while(1)
        {
            mega::CPrint("\n-* ",menu_name," *-\n\n");
            for(size_t i = 0; i < menu_container.size(); i++)
                mega::CPrint(menu_container[i].GetKey(),".) ",menu_container[i].GetName(),"\n");
            mega::CPrint("\n0.) Return/Exit\n\n");
            size_t input = mega::CGet<size_t>("Option: ");
            if(input == 0) return;
            if(input > 0 && input <= menu_container.size()) // Still trying to think of a nice way to incorporate range finding in CGet
            { mega::CPrint("\n\n"); menu_container[input-1].Call(); }
            else mega::CPrint("\n\nError: Invalid option.");
            mega::CPrint("\n\n");
        }
    }
};


You are going to need to change the mega::CPrint() && mega::CGet() functions as all of this code is part of my personal namespace. To keep things simple, change those functions to how you would normally cin and cout.

How this basically works is you create 2 vectors, one of the descriptions and the second is a vector of functions you would like to call according to that description.

The class automatically fills the "Keys" you have to press to access those functions.

Here is a basic example of the code being used:

1
2
3
4
Player player; // Generic object
MenuHandle PrintInventory = MakeHandle(&Player::PrintInventory,&player); // Make a MenuHandle from the addresses of the function to use and the object to use
Menu player_menu("Option selection",{"Print inventory"},{PrintInventory}); // Create the menu, first argument is the menu name, second is the vector of descriptions, third argument is the vector of MenuHandles
player_menu.Show(); // Show the menu, does not return until "0" is entered, meaning exit. 


I think it's quite nice, and found it very useful not just in text based RPG's, but other things as well.
Thank you, megatron. I will take your advice. I think I sort of understand what you are getting at. Also, thanks to everyone else who helped me. I figured the problem out.
Topic archived. No new replies allowed.