-1

In my class, I try to take a pointer to a method. In my case there are some methods with similar signatures. They are public methods.

The pointer is called Metric.

The compiler reports errors on a marked line:

D:\Job\Acronis\TestProblem\EmulationOfDisk\Emulate\CTesting.cpp:5: ошибка: cannot convert 'std::vector (CTesting::)()' to 'std::vector ()()' in assignment this->Metric = &this->ExTimeofWork;

I think it is a problem with the namespace. I tried to point to "CTesting::" near with a calling method. I could not fix this bug.

If I do the same construction out of class, it works.

Please, can you explain, why does this bug arise? How do I fix it?

class CTesting
{
    private:
        //code      
        vector<double> ( *Metric)();

    public:


        vector<double> ExTimeofWork();
        vector<double> ExTimeGenerationToAccept();
        vector<double> ExTimePoolToAccept();
        vector<double> ExMaxTimeGenerationToAccept();
        vector<double> ExMaxTimePoolToAccept();

        vector<double> GetTimeGenerationToAccept();
        vector<double> GetTimePoolToAccept();
        vector<double> GetTimeofWork();
};

void CTesting::Execute()
{
    this->Metric = &this->ExTimeofWork;//Ошибка!!!!!!!!!!!!!!!!!!!!
    //... Code

    //...
    return;
}
Chris Beck
  • 15,614
  • 4
  • 51
  • 87
hedgehogues
  • 217
  • 3
  • 21

2 Answers2

1

You need to declare Metric as pointer to member function:

class CTesting
{
    private:
        //code      
        vector<double> ( CTesting::*Metric)();

    public:
        vector<double> ExTimeofWork();
        void Execute();
};

void CTesting::Execute()
{
    this->Metric = &CTesting::ExTimeofWork;//Ошибка!!!!!!!!!!!!!!!!!!!!
    //... Code

    //...
    return;
}
Henrik
  • 23,186
  • 6
  • 42
  • 92
0

Also try just: this->Metric = &ExTimeofWork;

Dmytro Khmara
  • 1,200
  • 1
  • 8
  • 12