Hi I get this error message when trying to compile this :
template<typename T>
std::shared_ptr<T> sptr(T* ptr)
{
return std::shared_ptr<T>(ptr, &extension::IDeleteable::destroy);
}
costructorA(const Logger& _logger):logger(sptr(_logger.clone())) //here the error using sptr()
{}
logger is type : std::shared_ptr<Logger> logger;
class Logger
is :
class GMRISK_FCUL_API Logger : public IDeleteable{
public:
virtual ~Logger() {}
virtual void destroy() const =0;
};
class IDeleateable
:
class IDeleteable
{
public:
virtual void destroy() const =0;
template<typename T>
static inline void destroy(T* value)
{
value->destroy();
}
};
Here the complete error:
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludememory(725): error C2064: term does not evaluate to a function taking 1 arguments
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludememory(494) : see reference to function template instantiation 'void std::shared_ptr<_Ty>::_Resetp<_Ux,_Dx>(_Ux *,_Dx)' being compiled
with
[
_Ty=gmrisk::fcul::Logger,
_Ux=gmrisk::fcul::Logger,
_Dx=void (__thiscall extension::IDeleteable::* )(void) const
]
fcul_api.cpp(34) : see reference to function template instantiation 'std::shared_ptr<_Ty>::shared_ptr<T,void(__thiscall extension::IDeleteable::* )(void) const>(_Ux *,_Dx)' being compiled
with
[
_Ty=gmrisk::fcul::Logger,
T=gmrisk::fcul::Logger,
_Ux=gmrisk::fcul::Logger,
_Dx=void (__thiscall extension::IDeleteable::* )(void) const
]
Any idea which could produce this?
PD: the namespaces were not included here
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 } };
Are you perhaps used to using VB?
In VB arrays are done by using () but not in C/C++.
In C/C++ [] is used for arrays, but the other thing to remember is that it also dereferences pointers.
So if you use your function as something like
int main() { int max; int arr[] = {0, 1, 2, 3, 4}; max = maximum(arr, 5); return 0; }
Then values[0] will be 0, values[1] will be 1 and so on. You don’t need to add the extra * to get the value out.
So your for loop would be more like
for (size_t i = 0; i < numValues; i++) { if(values[i]) > values[i+1]) tempMax = values[i]; else tempMax = *(values + 1); }
But even then this still isn’t right. There are two problems left, your array will go right out of bounds on the last loop, and the else part will actually set the tempMax to the value in values[1]. You also aren’t taking into consideration the current value
of tempMax, so if the array is 5, 4, 3, 2, 1, depending on how lucky you are the value in tempMax leaving the for loop will either be 1 or some weird number that you will have no idea how it got there. If I was to write the function it would be more like.
int maximum(const int* values, size_t numValues) { int tempMax = 0x80000000; //initialise to a low value that you are going to get higher than //the value given here is the lowest negative number that int can store for (size_t i = 0; i < numValues; i++) { if(values[i] > tmpMax) tempMax = values[i]; //only update tempMax if the current value is larger than tempMax } return tempMax; }
The for condition of numValues — 1 will make sure we never go past the end of the array. But this is assuming that your function is there to return the largest number in the array.
This is a signature
Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts
is to aid in the learning process.
Visit my (not very good) blog at
http://ccprogramming.wordpress.com/
-
Marked as answer by
Wednesday, July 27, 2011 8:53 AM
- Forum
- Windows Programming
- «error C2064: term does not evaluate to
«error C2064: term does not evaluate to a function taking 1 arguments»
Hello
I just wrote this very simple program but i got the error «error C2064: term does not evaluate to a function taking 1 arguments», what in my program is wrong?
here it is:
//***********************************************************************
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
double x[19],tn;
for(i=0;i<19;i++)
{
x(i)=1;
//tn=x(i);
}
return 0;
}
and here is the error (when i double click on the error given below pointer goes to line 10,x(i)=1;)
—— Build started: Project: yj, Configuration: Debug Win32 ——
Compiling…
3.cpp
f:my projectyjyj3.cpp(9) : error C2064: term does not evaluate to a function taking 1 arguments
Build log was saved at «file://f:my projectyjyjDebugBuildLog.htm»
yj — 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
thanks in advance
Last edited on
problem is found!it must be x[i] not x(i).
Topic archived. No new replies allowed.
Я получил эту ошибку:
error C2064: term does not evaluate to a function taking 1 arguments
Я не знаю почему, но я обнаружил, что это что-то о потоках (если я закомментирую строки о потоках, которые он компилирует).
проблема в строках:
thread t(&TriviaServer::clientHandler, this->_socket);
а также:
thread t(&TriviaServer::clientHandler, client_socket);
из функций serve () и acceptClient.
мой код:
#include "TriviaServer.h"
#define PORT 8820
#define IFACE 0TriviaServer::TriviaServer()
{
this->_db = DataBase();
this->_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (this->_socket == INVALID_SOCKET)
throw exception(__FUNCTION__ " - socket");
}
TriviaServer::~TriviaServer()
{
for (unsigned int i = 0; i < this->_connectedUsers.size(); i++)
delete this->_connectedUsers[i];
this->_connectedUsers.clear();
for (unsigned int i = 0; i < this->_roomList.size(); i++)
delete this->_roomList[i];
this->_roomList.clear();
TRACE(__FUNCTION__ " closing accepting socket");
try
{
closesocket(this->_socket);
}
catch (exception e)
{
cout << e.what() << endl;
}
catch (...) {}
}
void TriviaServer::serve()
{
bindAndListen();
thread t(&TriviaServer::clientHandler, this->_socket);
t.detach();
while (true)
{
TRACE("accepting client...");
acceptClient();
}
}
void TriviaServer::bindAndListen()
{
struct sockaddr_in sockAddr = { 0 };
sockAddr.sin_port = PORT;
sockAddr.sin_family = AF_INET;
sockAddr.sin_addr.s_addr = IFACE;
if (::bind(this->_socket, (struct sockaddr*)&sockAddr, sizeof(sockAddr)) == SOCKET_ERROR)
throw exception(__FUNCTION__ " - bind");
TRACE("binded");
if (::listen(this->_socket, SOMAXCONN) == SOCKET_ERROR)
throw exception(__FUNCTION__ " - listen");
TRACE("listening...");
}
void TriviaServer::acceptClient()
{
SOCKET client_socket = accept(this->_socket, NULL, NULL);
if (client_socket == INVALID_SOCKET)
throw exception(__FUNCTION__);
TRACE("Client accepted !");
thread t(&TriviaServer::clientHandler, client_socket);
t.detach();
}
void TriviaServer::clientHandler(SOCKET)
{
//TODO
}
Кто-то знает причину и как это исправить?
1
Решение
thread t(&TriviaServer::clientHandler, this->_socket);
поскольку &TriviaServer::clientHandler
определяется как:
TriviaServer::clientHandler(SOCKET);
Первый аргумент, передаваемый вызову через указатель на функцию &TriviaServer::clientHandler
является неявным this
параметр типа TriviaServer
или указатель на объект TriviaServer
, Вам нужно передать это перед любым другим аргументом, который принимает объявление функции. Итак, вы хотите сделать:
thread t(&TriviaServer::clientHandler, this, this->_socket);
1
Другие решения
Других решений пока нет …
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
#include <iostream> #include <algorithm> #include <vector> #include <string> #include "conio.h" #include <list> #include <set> // программы предастовляет вам набор книг using namespace std; class Books { protected: string name; string author; float price; int year; public: Books() : name (), author () , price (), year () { } Books(string nName, string aAuthor, float pPrice, int yYear) : name(nName), author(aAuthor), price(pPrice), year(yYear) { } virtual ~Books() {} friend ostream& operator << (ostream&, Books&); friend istream& operator >> (istream&, Books&); friend bool operator != (const Books&,const Books&); void display() const { cout <<"Welcome to magazine"<< endl << name << ",t" << author << ",t" << year << "tt rub:" << price ; } virtual void getPages() = 0; }; class History : public Books { public: History(string n_name, string a_author, float p_price, int y_year):Books(n_name,a_author,p_price,y_year){} ~History() {} void getPages() { cout << "500" << endl; } }; class Drama : public Books { private: public: Drama(string nName, string aAuthor, float pPrice, int yYear):Books(nName,aAuthor,pPrice,yYear){} ~Drama() {} void getPages(){ cout << "464" << endl; } }; class Military : public Books { private: public: Military(string nName, string aAuthor, float pPrice, int yYear):Books(nName,aAuthor,pPrice,yYear) {} ~Military() {} void getPages(){ cout << "675" << endl; } }; class displayBooks { public: void operator() (const History*, Drama*, Military* ptrB ) const {ptrB->display();} }; class listOfBooks { private: vector <History*> &vectHist; vector <Drama*> &vectDrama; vector <Military*> &vectMil; public: listOfBooks(); ~listOfBooks(); void listhist() { History* ptrB1 = new History("eeee", "fdff",32321,321); History* ptrB2 = new History("eeee", "fdff",32321,321); History* ptrB3 = new History("eeee", "fdff",32321,321); cout << "Books a History" << endl; while(true) { cout << "wyberite nomer knigi kotory. hotite kupi 1,2,3 ili enter wozwrata" << endl; int n; cin >> n; switch(n) { case '1' : vectHist.push_back(ptrB1);break; case '2' : vectHist.push_back(ptrB2);break; case '3' : vectHist.push_back(ptrB3); break; case 'r' : cout << "Exitn" ;break; default : cout << "esczen"; } for_each(vectHist.begin(), vectHist.end(),displayBooks()); } void getPages(); } void listDrama() { cout << "Books a Drama" << endl; Drama* ptrB4 = new Drama( "fd","efter",55434,5345); Drama* ptrB5 = new Drama("fff", "eter",55434,5345); Drama* ptrB6 = new Drama("rtert", "eter",55434,5345); cout << "Books a Drama" << endl; while(true) { cout << "wyberite nomer knigi kotory. hotite kupi 1,2,3 ili enter wozwrata" << endl; int n; cin >> n; switch(n) { case '1' : vectDrama.push_back(ptrB4);break; case '2' : vectDrama.push_back(ptrB5);break; case '3' : vectDrama.push_back(ptrB6); break; default : cout << "esczen"; } for_each(vectDrama.begin(), vectDrama.end(),displayBooks()); } void getPages(); } void listMil() { cout << "Books a Military" << endl; Military* ptrB7 = new Military("ewqe","eqwe",333,33); Military* ptrB8 = new Military("ewqe","eqwe",333,33); Military* ptrB9 = new Military("ewqe","eqwe",333,33); while(true) { cout << "wyberite nomer knigi kotory. hotite kupi 1,2,3 ili enter wozwrata" << endl; int n; cin >> n; switch(n) { case '1' : vectMil.push_back(ptrB7); break; case '2' : vectMil.push_back(ptrB8); break; case '3' : vectMil.push_back(ptrB9); break; default : cout << "esczen"; } for_each(vectMil.begin(), vectMil.end(),displayBooks()); } void getPages(); } }; class InterfaceBooks { private: listOfBooks* ptrListBooks; public: InterfaceBooks() { ptrListBooks = new listOfBooks; } ~InterfaceBooks() { delete ptrListBooks; } void interAct() { int y; while(y != 'r') { cout << "n" << endl; int n; cin >> n; switch(n) { case '1' : void listhist(); cout << "" ; break; case '2' : void listDrama(); cout << "" ; break; case '3' : void listMil(); cout << "" ; break; case 'r' : cout << "Exitn" ;break;//нажатие Enter default : cout << "" ; } } } }; int main() { InterfaceBooks userinterface; userinterface.interAct(); getche(); return 0; } |
Recommended Answers
Hello,
The problem is, your function is called ‘perfect’ and your variable is too. You should change one of the two like so:
#include<iostream> using std::cin; using std::cout; using std::endl; int perfect (int); int main () { int number = 1; int p = 0; //instead …
Jump to Post
yep thats fine.. also make sure you return 0 when you declare int main(), otherwise declare void main()
The final program should look like this: (I changed the name of the function perfect(…) to perfect_function(…) and i added a return 0 at the end of main)#include …
Jump to Post
All 7 Replies
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
16 Years Ago
Hello,
The problem is, your function is called ‘perfect’ and your variable is too. You should change one of the two like so:
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int perfect (int);
int main ()
{
int number = 1;
int p = 0; //instead of perfect
//etc....
Edited
12 Years Ago
by Nick Evan because:
n/a
may4life
2
Junior Poster in Training
16 Years Ago
yep thats fine.. also make sure you return 0 when you declare int main(), otherwise declare void main()
The final program should look like this: (I changed the name of the function perfect(…) to perfect_function(…) and i added a return 0 at the end of main)
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int perfect_function (int);
int main ()
{
int number = 1;
int perfect = 0;
for(number=1; number < 1000; number++)
{
perfect = perfect_function(number); //here is where I call the function
if (perfect > 0)
{
cout << perfect << " is a perfect number." << endl;
cout << "It's factors are: ";
for ( int y = 1; y < perfect/2; y++ )
{
int divisor = perfect / y;
if ( perfect % y == 0 && y <= divisor)
{
cout << divisor << " " << y << endl;
}
} // ends factor perfect
} // ends if perfect
} // ends for to 1000
return 0;
}// ends main
int perfect_function (int counter) //here is where the function starts
{
int sum = 0;
int divisor = 0;
int y = 0;
for (y = 1; y < counter/2; y++)
{
divisor = counter / y;
if ( counter % y == 0 && y <= divisor)
{
int factors = y + divisor;
sum += factors;
}
}
if (sum - counter == counter)
{
return counter;
}
else
return 0;
}//ends function
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
16 Years Ago
otherwise declare void main()
Nope. Just use return 0;
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
16 Years Ago
… otherwise declare void main()
main()
is an int function and officially cannot be be declared as void. In fact, some compilers flag a warning if void is used. Forget what M$ claims in their help. They are wrong. :confused:
may4life
2
Junior Poster in Training
16 Years Ago
return 0 returns the number 0 (obviously.. hehe) to the Operating System. This is used to denote that the function main() was successfully completed. You can use void main() but as my friends above also noted, it is not recommended… so my final thoughts…DO use
int main()
...
return 0; // to the OS
13 Years Ago
perfect = perfect(number); //here is where I call the function
Well, the problem is that you have a variable (int perfect), as well as a function named perfect, which is not allowed, so you can either change the variable name, or the function name
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
13 Years Ago
Well, the problem is that you have a variable (int perfect), as well as a function named perfect, which is not allowed, so you can either change the variable name, or the function name
How is that any different from what I said 3 years ago in this same thread?
The problem is, your function is called ‘perfect’ and your variable is too. You should change one of the two
Lesson learned: Read thread first, reply later!
Edited
12 Years Ago
by Nick Evan because:
n/a
Reply to this topic
Be a part of the DaniWeb community
We’re a friendly, industry-focused community of developers, IT pros, digital marketers,
and technology enthusiasts meeting, networking, learning, and sharing knowledge.
class Student {
// ...
bool Graduate() { return m_bGraduate; }
// ...
};
class School {
vector<Student*> m_vecStudents;
void DelAndNullify(Student* &pStd);
void Fun1();
};
void School::DelAndNullify(Student* &pStd)
{
if ( (pStd != NULL) && (pStd->Graduate()) )
{
delete pStd;
pStd = NULL;
}
}
void School::Fun1()
{
for_each(m_vecStudents.begin(), m_vecStudents.end(), mem_fun(&School::DelAndNullify));
}
Error 1 error C2064: term does not evaluate to a function taking 1 arguments C:Program FilesMicrosoft Visual Studio 10.0VCincludealgorithm 22 1 Simulation
Why do I get this error?
updated
change Student
to pStd
updated // algorithm file
template<class _InIt, class _Fn1> inline
_Fn1 _For_each(_InIt _First, _InIt _Last, _Fn1 _Func)
{
// perform function for each element
for (; _First != _Last; ++_First)
_Func(*_First); // <<<<<<<< this line!
return (_Func);
}
BTW, if I define the DelAndNullify
as static
then the following line passes the compiler
for_each(m_vecStudents.begin(), m_vecStudents.end(), ptr_fun(&School::DelAndNullify));
Updated 05/09/2012
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <iostream>
#include <iomanip>
#include <functional>
#include <boost/bind.hpp>
class Student {
public:
Student(int id, bool bGraduate) : m_iID(id), m_bGraduate(bGraduate) {}
bool Graduate() const { return m_bGraduate; }
private:
int m_iID;
bool m_bGraduate;
};
class School {
public:
School(int numStudent)
{
for (int i=0; i<numStudent; ++i)
{
m_vecStudents.push_back(new Student(i+1, false));
}
}
~School()
{
// deallocate the allocated student resource to prevent memory leak!
}
void DelAndNullify(Student* &pStd);
void Fun1();
private:
std::vector<Student*> m_vecStudents;
};
void School::DelAndNullify(Student* &pStd)
{
if ( (pStd != NULL) && (!pStd->Graduate()) )
{
delete pStd;
pStd = NULL;
}
}
void School::Fun1()
{ // http://stackoverflow.com/questions/6065041/error-c2064-term-does-not-evaluate-to-a-function-taking-1-arguments
std::for_each(m_vecStudents.begin(), m_vecStudents.end(), std::bind1st(std::mem_fun(&School::DelAndNullify), this));
//boost::bind(&School::DelAndNullify, this, _1);
}
int main(int /*argc*/, char* /*argv*/[])
{
School school(10);
school.Fun1();
return 0;
}
Error 1 error C2535: ‘void std::binder1st<_Fn2>::operator ()(Student
*&) const’ : member function already defined or declared c:Program FilesMicrosoft Visual Studio 10.0VCincludexfunctional 299