vlad0995 0 / 0 / 1 Регистрация: 14.12.2013 Сообщений: 41 |
||||
1 |
||||
11.10.2014, 07:53. Показов 18299. Ответов 2 Метки нет (Все метки)
выдает ошибку, я посмотрел похожие темы, но ничего не помогло. в общем мож кто поймет в чем ошибка
0 |
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?
I am sorry but I forgot to put the whole code
#include <iostream>
#include <stdio.h>
#include <windows.h>
//==============================================================================
void VectorPrint(int nDim, double* pfVect)
{
int i;
printf(«——————————————————————n»);
for(i=0; i<nDim; i++)
{
printf(«%9.2lf «, pfVect[i]);
}
printf(«n»);
}
//==============================================================================
void MatrixPrint(int nDim, double* pfMatr)
{
int i,j;
printf(«——————————————————————n»);
for(i=0; i<nDim; i++)
{
for(j=0; j<nDim; j++)
{
printf(«%9.2lf «, pfMatr[nDim*i + j]);
}
printf(«n»);
}
}
//==============================================================================
// return 1 if system not solving
// nDim — system dimension
// pfMatr — matrix with coefficients
// pfVect — vector with free members
// pfSolution — vector with system solution
// pfMatr becames trianglular after function call
// pfVect changes after function call
//
// Developer: Henry Guennadi Levkin
//
//==============================================================================
int LinearEquationsSolving(int nDim, double* pfMatr, double* pfVect, double* pfSolution)
{
double fMaxElem;
double fAcc;
int i , j, k, m;
int fabs;
for(k=0; k<(nDim-1); k++) // base row of matrix
{
// search of line with max element
fMaxElem = fabs( pfMatr[k*nDim + k] );
m = k;
for(i=k+1; i<nDim; i++)
{
if(fMaxElem < fabs(pfMatr[i*nDim + k]) )
{
fMaxElem = pfMatr[i*nDim + k];
m = i;
}
}
// permutation of base line (index k) and max element line(index m)
if(m != k)
{
for(i=k; i<nDim; i++)
{
fAcc = pfMatr[k*nDim + i];
pfMatr[k*nDim + i] = pfMatr[m*nDim + i];
pfMatr[m*nDim + i] = fAcc;
}
fAcc = pfVect[k];
pfVect[k] = pfVect[m];
pfVect[m] = fAcc;
}
if( pfMatr[k*nDim + k] == 0.) return 1; // needs improvement !!!
// triangulation of matrix with coefficients
for(j=(k+1); j<nDim; j++) // current row of matrix
{
fAcc = — pfMatr[j*nDim + k] / pfMatr[k*nDim + k];
for(i=k; i<nDim; i++)
{
pfMatr[j*nDim + i] = pfMatr[j*nDim + i] + fAcc*pfMatr[k*nDim + i];
}
pfVect[j] = pfVect[j] + fAcc*pfVect[k]; // free member recalculation
}
}
for(k=(nDim-1); k>=0; k—)
{
pfSolution[k] = pfVect[k];
for(i=(k+1); i<nDim; i++)
{
pfSolution[k] -= (pfMatr[k*nDim + i]*pfSolution[i]);
}
pfSolution[k] = pfSolution[k] / pfMatr[k*nDim + k];
}
return 0;
}
//==============================================================================
// testing of function
//==============================================================================
#define MATRIX_DIMENSION 4
int main(int nArgs, char** pArgs)
{
int nDim = MATRIX_DIMENSION;
double fMatr[MATRIX_DIMENSION*MATRIX_DIMENSION] =
{
1.0, 2.0, -1.0, -2.0,
1.0, 3.0, -1.0, -2.0,
2.0, 1.0, 1.0, 1.0,
3.0, 1.0, 2.0, 1.0,
};
double fVec[MATRIX_DIMENSION] = {-6.0, -4.0, 11.0, 15.0};
double fSolution[MATRIX_DIMENSION];
int res;
int i;
void LinearEquationsSolving();
res = LinearEquationsSolving(nDim, fMatr, fVec, fSolution); // !!!
if(res)
{
printf(«No solution!n»);
return 1;
}
else
{
printf(«Solution:n»);
VectorPrint(nDim, fSolution);
}
return 0;
}
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 } };
Есть шаблонный класс для парсинга команд. Принцип такой: заполняется массив CmdList который содержит имя команды и указатель на метод в унаследованном классе от данного, сравниваем полученную команду с массивом и вызываем необходимый метод.
Вопрос такой: как правильно вызвать метод из этой структуры? Данный код вызывает ошибку компиляции.
Ошибка C2064 результатом вычисления фрагмента не является функция, принимающая 1 аргументов
#ifndef _CONSOLECMDS_H
#define _CONSOLECMDS_H
#include <string>
#include <vector>
template<class T>
class ConsoleCmds
{
protected:
struct CmdList_t
{
std::string cmd = "";
errno_t (T::*function)(std::vector<std::string>) = NULL;
};
private:
std::vector<CmdList_t> CmdList;
protected:
errno_t CMD_ERROR = -1;
ConsoleCmds() {}
~ConsoleCmds() {}
void InitCmdList(std::vector<CmdList_t> list)
{
CmdList = list;
}
errno_t ParseCmd(std::vector<std::string> cmdArr)
{
errno_t err = CMD_ERROR;
for (size_t i = 0; i < CmdList.size(); ++i)
{
if (CmdList[i].cmd == cmdArr[0])
{
cmdArr.erase(cmdArr.begin());
err = CmdList[i].function(cmdArr); //??????????
return (err);
}
}
return (err);
}
};
#endif //_CONSOLECMDS_H