description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
---|---|---|---|---|---|
Learn more about: Compiler Error C2064 |
Compiler Error C2064 |
11/04/2016 |
C2064 |
C2064 |
6cda05da-f437-4f50-9813-ae69538713a3 |
Compiler Error C2064
term does not evaluate to a function taking N arguments
A call is made to a function through an expression. The expression does not evaluate to a pointer to a function that takes the specified number of arguments.
In this example, the code attempts to call non-functions as functions. The following sample generates C2064:
// C2064.cpp int i, j; char* p; void func() { j = i(); // C2064, i is not a function p(); // C2064, p doesn't point to a function }
You must call pointers to non-static member functions from the context of an object instance. The following sample generates C2064, and shows how to fix it:
// C2064b.cpp struct C { void func1(){} void func2(){} }; typedef void (C::*pFunc)(); int main() { C c; pFunc funcArray[2] = {&C::func1, &C::func2}; (funcArray[0])(); // C2064 (c.*funcArray[0])(); // OK - function called in instance context }
Within a class, member function pointers must also indicate the calling object context. The following sample generates C2064 and shows how to fix it:
// C2064d.cpp // Compile by using: cl /c /W4 C2064d.cpp struct C { typedef void (C::*pFunc)(); pFunc funcArray[2]; void func1(){} void func2(){} C() { funcArray[0] = &C::func1; funcArray[1] = &C::func2; } void func3() { (funcArray[0])(); // C2064 (this->*funcArray[0])(); // OK - called in this instance context } };
I’m trying to use STL, but the following doesn’t compile. main.cpp:
#include <set>
#include <algorithm>
using namespace std;
class Odp
{
public:
set<int> nums;
bool IsOdd(int i)
{
return i % 2 != 0;
}
bool fAnyOddNums()
{
set<int>::iterator iter = find_if(nums.begin(), nums.end(), &Odp::IsOdd);
return iter != nums.end();
}
};
int main()
{
Odp o;
o.nums.insert(0);
o.nums.insert(1);
o.nums.insert(2);
}
The error is:
error C2064: term does not evaluate to a function taking 1 arguments
1> c:program filesmicrosoft visual studio 10.0vcincludealgorithm(95) : see reference to function template instantiation '_InIt std::_Find_if<std::_Tree_unchecked_const_iterator<_Mytree>,_Pr>(_InIt,_InIt,_Pr)' being compiled
1> with
1> [
1> _InIt=std::_Tree_unchecked_const_iterator<std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>>,
1> _Mytree=std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>,
1> _Pr=bool (__thiscall Odp::* )(int)
1> ]
1> main.cpp(20) : see reference to function template instantiation '_InIt std::find_if<std::_Tree_const_iterator<_Mytree>,bool(__thiscall Odp::* )(int)>(_InIt,_InIt,_Pr)' being compiled
1> with
1> [
1> _InIt=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>>,
1> _Mytree=std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>,
1> _Pr=bool (__thiscall Odp::* )(int)
1> ]
What am I doing wrong?
Hi guys,
I am facing «error C2064: term does not evaluate to a function taking 1 arguments» in this program during compiler.
Please help.
Cheers,
Dev
#include <iostream>
#include <cctype> //For toupper
using namespace std;
//function declarations
//public variable
//main
int main()
{
// Variable Declarations
char Reply = ‘ ‘;
char ReadChar;
int selectnum; /* defines input*/
int GetResult; /* defines conversion input*/
int results[5]={0,0,0,0,0}; /* Initialise Array*/
cout << «n ********* Welcome to C++ Program for Managing Exam Results ********nn»; /*Displays Title*/
cout << » 1. Read and Store Exam Resultsn»;
cout << » 2. Sort and Display Results in Ascending Ordern»;
cout << » 3. Calculate Fail Raten»;
cout << » 4. Search for a particular Resultn»;
cout << » 5. Display All Resultn»;
cout << » 6. Exitnnn»;
cout << » Enter 1/2/3/4/5/6: «;
cin>>selectnum;
while(selectnum > 6) /* While loop to ensure no number > 6 is inputted*/
{
cout << «ntError! Please enter a number between 1 to 6. na»;
cout << «n ********* Welcome to C++ Program for Managing Exam Results ********nn»; /*Displays Title*/
cout << » 1. Read and Store Exam Resultsn»;
cout << » 2. Sort and Display Results in Ascending Ordern»;
cout << » 3. Calculate Fail Raten»;
cout << » 4. Search for a particular Resultn»;
cout << » 5. Display All Resultn»;
cout << » 6. Exitnnn»;
cout << » Enter 1/2/3/4/5/6: «;
cin >> selectnum;
}
while ((selectnum > 0 )&&(selectnum < 6)) /* While loop to allow multiple selection*/
{
switch (selectnum) /* Switch…Case to compare a variable to several integral values */
{
case 1: /*Read and Store Exam Results*/
cout << «The current Results are:n»<<endl
<<«{0,0,0,0,0}»;
cout<<«Do you wish to update the result? (Y/N): «;
ReadChar(Reply); // ERROR LINE
Reply=toupper(Reply); //Convert to uppercase
while ((Reply!=’N’)&& (Reply!=’Y’))
{
cout<<«nInvalid Entry. Try again.»<<endl
<<«Please enter Y or N ==>»;
ReadChar(Reply); // ERROR LINE
Reply=toupper(Reply);
}
if (Reply == ‘Y’)
{
cin >> GetResult;
}
else if (Reply==’N’)
{
cout << «n ********* Welcome to C++ Program for Managing Exam Results ********nn»; /*Displays Title*/
cout << » 1. Read and Store Exam Resultsn»;
cout << » 2. Sort and Display Results in Ascending Ordern»;
cout << » 3. Calculate Fail Raten»;
cout << » 4. Search for a particular Resultn»;
cout << » 5. Display All Resultn»;
cout << » 6. Exitnnn»;
cout << » Enter 1/2/3/4/5/6: «;
}
while (selectnum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << «nnError! Please enter a number between 1 to 6. n»;
cout << «n ********* Welcome to C++ Program for Managing Exam Results ********nn»; /*Displays Title*/
cout << » 1. Read and Store Exam Resultsn»;
cout << » 2. Sort and Display Results in Ascending Ordern»;
cout << » 3. Calculate Fail Raten»;
cout << » 4. Search for a particular Resultn»;
cout << » 5. Display All Resultn»;
cout << » 6. Exitnnn»;
cout << » Enter 1/2/3/4/5/6: «;
cin >> selectnum;
}
break;
}
}
}
ilya312 0 / 0 / 0 Регистрация: 04.12.2016 Сообщений: 13 |
||||
1 |
||||
07.03.2017, 14:37. Показов 4156. Ответов 11 Метки нет (Все метки)
Помогите исправить ошибку :результатом вычисления фрагмента не является функция, принимающая 2 аргументов Кликните здесь для просмотра всего текста
0 |
7533 / 6396 / 2916 Регистрация: 14.04.2014 Сообщений: 27,859 |
|
07.03.2017, 14:46 |
2 |
Нужно именно в таком виде реализовать? Лямбда-выражение почему не используешь?
0 |
0 / 0 / 0 Регистрация: 04.12.2016 Сообщений: 13 |
|
07.03.2017, 14:50 [ТС] |
3 |
Да , нужно использовать функциональный класс
0 |
8725 / 4305 / 958 Регистрация: 15.11.2014 Сообщений: 9,752 |
|
07.03.2017, 16:06 |
4 |
Помогите исправить ошибку :результатом вычисления фрагмента не является функция, принимающая 2 аргументов скобки не правильно расставлены.
в одну строку должны страдать.
0 |
0 / 0 / 0 Регистрация: 04.12.2016 Сообщений: 13 |
|
07.03.2017, 17:15 [ТС] |
5 |
А что в скобочках не так? так тоже не работает
0 |
187 / 54 / 19 Регистрация: 23.12.2016 Сообщений: 165 |
|
07.03.2017, 18:40 |
6 |
Я насчитал 7 открывающих скобок и только 6 закрывающих. Добавлено через 6 минут
0 |
Вездепух 10921 / 5916 / 1615 Регистрация: 18.10.2014 Сообщений: 14,868 |
|
07.03.2017, 18:46 |
7 |
результатом вычисления фрагмента не является функция, принимающая 2 аргументов Ну так, как вам ясно сказал компилятор, Далее вы пихаете этот унарный функтор в
1 |
8725 / 4305 / 958 Регистрация: 15.11.2014 Сообщений: 9,752 |
|
07.03.2017, 19:03 |
8 |
так тоже не работает а с фига ему работать,
0 |
Вездепух 10921 / 5916 / 1615 Регистрация: 18.10.2014 Сообщений: 14,868 |
|
07.03.2017, 19:05 |
9 |
P.S. Отдельно стоит заметить, что
1 |
0 / 0 / 0 Регистрация: 04.12.2016 Сообщений: 13 |
|
07.03.2017, 19:46 [ТС] |
10 |
Мне нужно убрать из дека все числа, кроме первого , которые делятся на N
0 |
Вездепух 10921 / 5916 / 1615 Регистрация: 18.10.2014 Сообщений: 14,868 |
|
07.03.2017, 19:57 |
11 |
Мне нужно убрать из дека все числа, кроме первого , которые делятся на N Тогда
1 |
0 / 0 / 0 Регистрация: 04.12.2016 Сообщений: 13 |
|
07.03.2017, 20:00 [ТС] |
12 |
Всем спасибо!)
0 |
I am writing a class which uses a thread and I wanted to try the new C++11 std::thread
. I am compiling with Microsoft Visual Studio Pro 2013 v12.0.31101.00 Update 4. The update is from Nov 2014 so is fairly up-to-date. I can use std::thread
for simple uses but in my code below I get compiler errors.
If I comment out the initialization of the thread, as in:
serial(int port) : port_(port) {} //, reader_thread(&serial::reader_thread_func) {}
Then it compiles ok.
How can I fix this?
Here is my code.
serial.hpp:
/* serial port class */
#ifndef SERIAL_
#define SERIAL_
#include <thread>
class serial
{
public:
serial(int port) : port_(port), reader_thread(&serial::reader_thread_func) {}
~serial();
bool open();
bool close();
private:
std::thread reader_thread;
void reader_thread_func();
int port_;
};
#endif // SERIAL_
serial.cpp:
#include <iostream>
#include "serial.hpp"
void serial::reader_thread_func() {
std::cout << "reader thread running with thread id: " << std::this_thread::get_id() << 'n';
}
serial::~serial() {
close();
}
bool serial::open() {
close(); // in case we are already open
std::cout << "opening port " << port_ << 'n';
return true;
}
bool serial::close() {
std::cout << "closing port " << port_ << 'n';
return false;
}
main.cpp to drive:
#include "serial.hpp"
int main() {
serial s(3);
s.open();
s.close();
}
Compiler errors:
1>------ Build started: Project: thread_in_class, Configuration: Debug Win32 ------
1> serial.cpp
1>c:program files (x86)microsoft visual studio 12.0vcincludefunctional(1149): error C2064: term does not evaluate to a function taking 0 arguments
1> class does not define an 'operator()' or a user defined conversion operator to a pointer-to-function or reference-to-function that takes appropriate number of arguments
1> c:program files (x86)microsoft visual studio 12.0vcincludefunctional(1137) : see reference to function template instantiation 'void std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>::_Do_call<,>(std::tuple<>,std::_Arg_idx<>)' being compiled
1> c:program files (x86)microsoft visual studio 12.0vcincludefunctional(1137) : see reference to function template instantiation 'void std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>::_Do_call<,>(std::tuple<>,std::_Arg_idx<>)' being compiled
1> c:program files (x86)microsoft visual studio 12.0vcincludethrxthread(195) : see reference to function template instantiation 'void std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>::operator ()<>(void)' being compiled
1> c:program files (x86)microsoft visual studio 12.0vcincludethrxthread(195) : see reference to function template instantiation 'void std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>::operator ()<>(void)' being compiled
1> c:program files (x86)microsoft visual studio 12.0vcincludethrxthread(192) : while compiling class template member function 'unsigned int std::_LaunchPad<_Target>::_Run(std::_LaunchPad<_Target> *)'
1> with
1> [
1> _Target=std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>
1> ]
1> c:program files (x86)microsoft visual studio 12.0vcincludethrxthread(187) : see reference to function template instantiation 'unsigned int std::_LaunchPad<_Target>::_Run(std::_LaunchPad<_Target> *)' being compiled
1> with
1> [
1> _Target=std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>
1> ]
1> c:program files (x86)microsoft visual studio 12.0vcincludethrxthread(205) : see reference to class template instantiation 'std::_LaunchPad<_Target>' being compiled
1> with
1> [
1> _Target=std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>
1> ]
1> c:program files (x86)microsoft visual studio 12.0vcincludethread(49) : see reference to function template instantiation 'void std::_Launch<std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>>(_Thrd_t *,_Target &&)' being compiled
1> with
1> [
1> _Target=std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>
1> ]
1> c:usersangusdocumentsvisual studio 2013projectsthread_in_classthread_in_classserial.hpp(10) : see reference to function template instantiation 'std::thread::thread<void(__thiscall serial::* )(void),>(_Fn &&)' being compiled
1> with
1> [
1> _Fn=void (__thiscall serial::* )(void)
1> ]
1> main.cpp
1>c:program files (x86)microsoft visual studio 12.0vcincludefunctional(1149): error C2064: term does not evaluate to a function taking 0 arguments
1> class does not define an 'operator()' or a user defined conversion operator to a pointer-to-function or reference-to-function that takes appropriate number of arguments
1> c:program files (x86)microsoft visual studio 12.0vcincludefunctional(1137) : see reference to function template instantiation 'void std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>::_Do_call<,>(std::tuple<>,std::_Arg_idx<>)' being compiled
1> c:program files (x86)microsoft visual studio 12.0vcincludefunctional(1137) : see reference to function template instantiation 'void std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>::_Do_call<,>(std::tuple<>,std::_Arg_idx<>)' being compiled
1> c:program files (x86)microsoft visual studio 12.0vcincludethrxthread(195) : see reference to function template instantiation 'void std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>::operator ()<>(void)' being compiled
1> c:program files (x86)microsoft visual studio 12.0vcincludethrxthread(195) : see reference to function template instantiation 'void std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>::operator ()<>(void)' being compiled
1> c:program files (x86)microsoft visual studio 12.0vcincludethrxthread(192) : while compiling class template member function 'unsigned int std::_LaunchPad<_Target>::_Run(std::_LaunchPad<_Target> *)'
1> with
1> [
1> _Target=std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>
1> ]
1> c:program files (x86)microsoft visual studio 12.0vcincludethrxthread(187) : see reference to function template instantiation 'unsigned int std::_LaunchPad<_Target>::_Run(std::_LaunchPad<_Target> *)' being compiled
1> with
1> [
1> _Target=std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>
1> ]
1> c:program files (x86)microsoft visual studio 12.0vcincludethrxthread(205) : see reference to class template instantiation 'std::_LaunchPad<_Target>' being compiled
1> with
1> [
1> _Target=std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>
1> ]
1> c:program files (x86)microsoft visual studio 12.0vcincludethread(49) : see reference to function template instantiation 'void std::_Launch<std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>>(_Thrd_t *,_Target &&)' being compiled
1> with
1> [
1> _Target=std::_Bind<true,void,std::_Pmf_wrap<void (__thiscall serial::* )(void),void,serial,>,>
1> ]
1> c:usersangusdocumentsvisual studio 2013projectsthread_in_classthread_in_classserial.hpp(10) : see reference to function template instantiation 'std::thread::thread<void(__thiscall serial::* )(void),>(_Fn &&)' being compiled
1> with
1> [
1> _Fn=void (__thiscall serial::* )(void)
1> ]
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========