Ошибка c2064 результатом вычисления фрагмента не является функция принимающая 1 аргументов

class Student { // ... bool Graduate() { return m_bGraduate; } // ... }; class School { vector m_vecStudents; void DelAndNullify(Student* &pStd); void ...
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

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

  • Remove From My Forums
  • Question

  • Hello ..,
    I try make small app in vc++ 2008 and i try it too in vc++ 2005 but it’s the same :(, i use dataSet and code will say what I need too say

    1 DataSet^ DataS; 
    2 array<Object^, 1>^ Info1 = gcnew array<Object^, 1>(4); 
    3 Info1[0] = DataS->Tables[0]->Rows(DataS->Tables[0]->Rows->Count — 1)[0] + 1; 

    the error in line 3, I got error C2064: term does not evaluate to a function taking 1 arguments.

    AmR EiSa.

    • Edited by

      Friday, June 6, 2008 7:01 AM
      change ,3 to 3,

Answers

  • You do need square brackets to index the Rows property.  Your next problem is that you are trying to add 1 to an Object^.  It helps to break down the statement:

      DataRow^ row = DataS->Tables[0]->Rows[DataS->Tables[0]->Rows->Count — 1];
      Object^ column = row[0];
      int value = (int)column + 1;

    Putting it back together:

      int value = 1 + (int)(DataS->Tables[0]->Rows[DataS->Tables[0]->Rows->Count — 1][0]);


    Hans Passant.

    • Proposed as answer by
      AmR EiSa
      Sunday, June 8, 2008 1:25 PM
    • Marked as answer by
      Yan-Fei Wei
      Monday, June 9, 2008 7:46 AM

  • Remove From My Forums
  • Question

  • Hello ..,
    I try make small app in vc++ 2008 and i try it too in vc++ 2005 but it’s the same :(, i use dataSet and code will say what I need too say

    1 DataSet^ DataS; 
    2 array<Object^, 1>^ Info1 = gcnew array<Object^, 1>(4); 
    3 Info1[0] = DataS->Tables[0]->Rows(DataS->Tables[0]->Rows->Count — 1)[0] + 1; 

    the error in line 3, I got error C2064: term does not evaluate to a function taking 1 arguments.

    AmR EiSa.

    • Edited by

      Friday, June 6, 2008 7:01 AM
      change ,3 to 3,

Answers

  • You do need square brackets to index the Rows property.  Your next problem is that you are trying to add 1 to an Object^.  It helps to break down the statement:

      DataRow^ row = DataS->Tables[0]->Rows[DataS->Tables[0]->Rows->Count — 1];
      Object^ column = row[0];
      int value = (int)column + 1;

    Putting it back together:

      int value = 1 + (int)(DataS->Tables[0]->Rows[DataS->Tables[0]->Rows->Count — 1][0]);


    Hans Passant.

    • Proposed as answer by
      AmR EiSa
      Sunday, June 8, 2008 1:25 PM
    • Marked as answer by
      Yan-Fei Wei
      Monday, June 9, 2008 7:46 AM

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Ошибка check vsc лексус is 250
  • Ошибка ce 100005 6 playstation 5
  • Ошибка c2006 mazda cx5
  • Ошибка check vsc system на lexus lx570
  • Ошибка cda6 bmw

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии