Menu

allocator error (Bug?)

Anonymous
2003-03-02
2012-09-26
  • Anonymous

    Anonymous - 2003-03-02

    Well i got it all working properly. Turns out the problem was evidently Dev-C++. The below code runs in Visual C++, Borland Builder 6.0 and CodeWarrior, but not in Dev-C++. Below is the errors received and below that is the code.
    line1:
    /Dev-Cpp/Bin/../lib/gcc-lib/mingw32/2.95.3-6/../../../../include/g++-3/stl_alloc.h C:\Documents and Settings\Gary Register\My Documents\code\FunctionPointer\examples\C
    In instantiation of `allocator<int (FPclass::*)()>':

    line2:
    25 C:\Documents and Settings\Gary Register\My Documents\code\FunctionPointer\examples\Untitled1.cpp
    instantiated from here

    line3:
    750 C:\Dev-Cpp\include\g++-3\stl_alloc.h
    `allocator<int (FPclass::*)()>::address(int (FPclass::* &)()) const' has already been declared in `allocator<int (FPclass::*)()>'

    // Here the working code for all other compilers

    // fp.cpp : Investigation of vector <member function pointers> v;
    // #include "stdafx.h" // only used in Visual C++
    #include <iostream>
    #include <stdlib.h>
    #include <string>
    #include <vector>

    using namespace std;

    class FPclass
    {
    public:
    FPclass();
    ~FPclass();
    int CallMemberFunction(int option);
    int number_of_functions();
    private:
    int func0(void);
    int func1(void);
    int func2(void);
    int func3(void);
    typedef int (FPclass::*FuncPointer)(void);
    vector<FuncPointer> functions;
    };

    FPclass::FPclass()
    {
    functions.push_back(&FPclass::func0);
    functions.push_back(&FPclass::func1);
    }

    FPclass::~FPclass() {}

    int FPclass::number_of_functions()
    {
    return functions.size();
    }

    int FPclass::CallMemberFunction(int option)
    {
    if (option < functions.size()) {
    (this->*functions[option])();
    }
    return 1;
    }

    int FPclass::func0(void)
    {
    cout << "member function 0 has been called" << endl;
    return 1;
    }
    int FPclass::func1(void)
    {
    cout << "member function 1 has been called" << endl;
    return 1;
    }

    //***********************************************

    int main(int argc, char* argv[])
    {
    FPclass fp;

    for (int i =0; i<fp.number_of_functions();i++)
    fp.CallMemberFunction(i);

    return 0;
    }

     
    • Anonymous

      Anonymous - 2003-03-02

      Incidently, this code also works with g++ on SunOS. I understand that Dev-C++ is just a front end product. This code however may point out an issue with  g++ under mingw. I'm not sure what it points out to developers whom may be interested, but this has been compiled and run under several compilers with no errors.
      Thanks

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.