a3.cpp(75): error C2563: mismatch in formal parameter list
I’m certain I’m passing the function checkout with 3 doubles, I don’t know why I’m getting the error I am. Please help.
#include <iostream>
#include <cstdlib>
using namespace std;
const double peanut_PRICE = 1.80;
const double peanut_SHIP = 0.50;
const double BOOK_PRICE = 9;
const double BOOK_SHIP = 1.06;
const double MOVIE_PRICE = 13.99;
const double MOVIE_SHIP = 0.05;
double checkout (double myamountofbooks, double myamountofmovies, double mypoundsofpeanuts)
{
myamountofbooks = myamountofbooks * (BOOK_PRICE + BOOK_SHIP);
myamountofmovies = myamountofmovies * MOVIE_PRICE * (1 + MOVIE_SHIP);
mypoundsofpeanuts = mypoundsofpeanuts * (peanut_PRICE + peanut_SHIP);
return (myamountofbooks + myamountofmovies + mypoundsofpeanuts);
}
bool validUserImput (int whereUserWantsToGoNext)
{
if (whereUserWantsToGoNext > 50 || whereUserWantsToGoNext < 0)
return false;
else return true;
}
bool validUserImput (double whereUserWantsToGoNext)
{
if (whereUserWantsToGoNext > 50 || whereUserWantsToGoNext < 0)
return false;
else return true;
}
int main()
{
//===========================Declaration Statements==================================
double amountofbooks = 0;
double amountofmovies = 0;
double poundsofpeanuts = 0;
int whereUserWantsToGoNext = 0;
while (! (whereUserWantsToGoNext == 4) )
{
cout << "1. Booksn2. Peanutsn3. Moviesn4. Checkoutn" << endl;
cin >> whereUserWantsToGoNext;
if (!validUserImput(whereUserWantsToGoNext)) cout << "INVALID IMPUT" << endl;
if (whereUserWantsToGoNext == 1){
cout << "Please enter your number of books";
cin >> amountofbooks;
if (!validUserImput(amountofbooks)) cout << "INVALID IMPUT" << endl;
}
if (whereUserWantsToGoNext == 3){
cout << "Now please enter the number of movies you've selected";
cin >> amountofmovies;
if (!validUserImput(amountofmovies)) cout << "INVALID IMPUT" << endl;
}
if (whereUserWantsToGoNext == 2) {
cout << "Please enter the weight(in pounds) of your peanuts";
cin >> poundsofpeanuts;
if (!validUserImput(poundsofpeanuts)) cout << "INVALID IMPUT" << endl;
}
if (validUserImput == 4) cout << "Total Cost is..." << checkout(amountofbooks, amountofmovies, poundsofpeanuts);
}
cin >> amountofbooks;
}
BenMorel
33.5k49 gold badges174 silver badges310 bronze badges
asked Oct 27, 2010 at 18:50
2
The problem is here:
if (validUserImput == 4) ...
validUserImput
is a function, but you are not calling that function, you are trying to compare it to 4
.
If you wanted to keep track of the number of valid inputs you received, you could instead add a new variable that you manually increment on every valid input.
answered Oct 27, 2010 at 19:01
sthsth
218k53 gold badges277 silver badges364 bronze badges
The last if — you are comparing function pointer to an integer. try this:
if (validUserImput(3) == 4) cout << "Total Cost is..." << checkout(amountofbooks, amountofmovies, poundsofpeanuts);
answered Oct 27, 2010 at 18:57
BЈовићBЈовић
61.3k41 gold badges174 silver badges266 bronze badges
2
I assume you want to display the result of the checkout
function if the user selects 4
. So you probably wanted to write:
if (whereUserWantsToGoNext == 4) cout << "Total Cost is..." << checkout(amountofbooks, amountofmovies, poundsofpeanuts) << endl;
answered Oct 27, 2010 at 19:07
Charles SalviaCharles Salvia
51.7k12 gold badges127 silver badges140 bronze badges
- Remove From My Forums
-
Question
-
Hi,
atm I am porting a project from VS 2013 Update 4 to the new VS 2015. Most things works without problem, but now I have a compile error I can’t understand. I made a screenshot of the source.
‘createFunc’ of data has the type ‘void*’. ‘createProcessModule’ is a template function. Now I want to store the address of the explicitly created function in this pointer variable. This results in ‘error C2563: mismatch in formal parameter list’.
But if I store the address in a local variable created with autom then it works. This is confusing for me and I would like to know why.
Answers
-
The C++ standard says that that template functions are to be treated as overloaded functions in this case:
«13.4/1 A use of an overloaded function name without arguments is resolved in certain contexts to a function, a pointer to function or a pointer to member function for a specific function from the overload set. A function template name is considered
to name a set of overloaded functions in such contexts. The function selected is the one whose type is identical to the function type of the target type required in the context.»The type required in this context happens to be «void*». Not only that «void*» doesn’t carry enough information to allow overload resolution to be performed but if you follow the standard strictly (VC++ doesn’t) it’s not even
possible to convert a function pointer to «void*».That said, I find rather peculiar that this works if you assign to an auto variable but Clang and GCC behave like this as well. If 3 different compilers complain about this kind of code then you can conclude that the code is indeed incorrect.
IMO a better solution than using auto is to case to the expected pointer type:
data.createFunc = static_cast<void*(*)()>(createProcessModule<ModuleType>);
-
Marked as answer by
Tuesday, August 18, 2015 2:37 AM
-
Marked as answer by
Skeever 0 / 0 / 0 Регистрация: 17.11.2019 Сообщений: 227 |
||||
1 |
||||
09.02.2020, 20:34. Показов 2683. Ответов 6 Метки cpp (Все метки)
Доброго времени суток, можете пожалуйста пояснить природу этой ошибки? Задание сделать шаблоны функций инициализации и вывода массива. Тема для меня сырая, некоторые задачи поделал. а вот с этой никак не выходит. С первой функцией проблем нет,а вот вторая выдает вышеуказанную ошибку.
__________________
0 |
Нарушитель 8388 / 4391 / 1009 Регистрация: 12.03.2015 Сообщений: 20,566 |
|
09.02.2020, 20:38 |
2 |
На этапе компиляции ошибка-то?
1 |
elenayagubova 337 / 237 / 103 Регистрация: 26.03.2019 Сообщений: 407 |
||||
09.02.2020, 21:45 |
3 |
|||
Сообщение было отмечено d8veloper как решение Решениеошибку вижу, но другую
for (int i = 0; i < size; i++) {
1 |
0 / 0 / 0 Регистрация: 17.11.2019 Сообщений: 227 |
|
09.02.2020, 21:59 [ТС] |
4 |
elenayagubova, в ней и дело,спасибо. Преимущества свежего взгляда очевидны ))
0 |
337 / 237 / 103 Регистрация: 26.03.2019 Сообщений: 407 |
|
09.02.2020, 22:03 |
5 |
d8veloper, вообще нормальный компилятор должен был подчеркнуть это место с вопросом «что? не знаю я никакого size!» ))
0 |
0 / 0 / 0 Регистрация: 17.11.2019 Сообщений: 227 |
|
09.02.2020, 22:07 [ТС] |
6 |
elenayagubova, я уже об этом подумал.Надо будет преподавателя спросить.
0 |
Mental handicap 1245 / 623 / 171 Регистрация: 24.11.2015 Сообщений: 2,429 |
|
09.02.2020, 22:18 |
7 |
я уже об этом подумал.Надо будет преподавателя спросить. Так он вам ошибку и выдал: Compiler Error C2563 The formal parameter list of a function (or a pointer to a function) does not match those of another function (or pointer to a member function). As a result, the assignment of functions or pointers cannot be made. Compiler Error C2563
0 |
For a homework assignment we were provided with two header files. One contains the base class prototypes and definitions for a linked list. The other contains derived class prototypes and definitions for an unordered linked list. They were supposed to work just fine and be code we just stuck in our project and only called the functions for in the main function we built as the homework assignment. However I received a number of errors when I tried to compile. As part of fixing the errors the only change I’ve made to the unorderedLinkedList header file was adding
using linkedListType<Type>::first;
using linkedListType<Type>::last;
at the top because otherwise it was not recognizing the variables first and last from the base class. Now the only errors left are «mismatch in formal parameter list» for lines 84, 111, and 170 in unorderedLinkedList.h Two hours of Google haven’t helped me. As best I can tell the parameters in the function headings match the prototypes perfectly.
I’ve copied both the linkedList.h and unorderdLinkedList.h into a GitHub repository. I’m afraid I’m not familiar with GitHub, but I made it public, so hopefully this works. On another post I saw someone suggest using GitHub to share code for questions like this. This is my first Reddit post; so if I am doing anything wrong I would be happy to correct the style of this post.
Я пытаюсь сделать класс для задания. Предполагается, что он записывает, сколько времени требуется программе для запуска и сколько раз повторяется цикл, а затем помещает эту информацию в файл. Прямо сейчас он дает мне:
error 2298 "missing call to bound pointer to member function"
А также
error 2563 "mismatch in formal parameter list."
Мне трудно понять, как это исправить; это, вероятно, менее сложно, чем я делаю это, но любая помощь будет оценена по достоинству.
#include <thread>
#include <iostream>
#include <fstream>
#include <chrono>
#include <string>
using namespace std;
class Timer {
private:
typedef chrono::high_resolution_clock Clock;
Clock::time_point epoch;
public:
Timer() {
epoch = Clock::now();
}
Clock::duration getElapsedTime() { return Clock::now() - epoch; }
};
int loopCount()
{
for (int count=0;count<=100;) {
count++;
}
return count;
}
int fProjectDebugFile()
{
fstream debugFile;
debugFile.open ("FinalProjectDebugger.txt", fstream::out | fstream::app);
string jar(Timer);
cout << jar << endl << loopCount() << endl;
debugFile.close();
return 0;
}
1 ответ
Вы не можете получить доступ к переменным цикла вне цикла.
Итак, переместите объявление за пределы цикла, т.е. замените это:
int loopCount(){
for(int count=0;count<=100;){
count++;}
return count;
}
С этим:
int loopCount()
{
int count = 0;
while (count <= 100)
{
count++;
}
return count;
}
Также это:
class Timer
...
string jar(Timer);
Не имеет большого смысла. Timer
— это тип, поэтому string jar(Timer);
объявляет функцию с именем jar
, которая принимает объект Timer
в качестве параметра и возвращает string
.
1
Sid S
7 Дек 2019 в 08:12