0

I've made a pointer to a function, initDrop(unsigned int), and I get an error in visual studio, C2064, which states "term does not evaluate to a function taking 1 arguments".

Here's the important parts of the header file


namespace noise
{
    namespace module
    {
        class ErosionModule : public Module
        {
        public:

            void iterate(unsigned int iterations, unsigned int strength);

        protected:

            void initDrop(unsigned int iterations);
        };

        class Raindrop : public ErosionModule
        {
        public:

            void calculate();

        };
    }
}

and heres the important parts of the cpp file that are failing, with the error line being on the call to funcRef(1000).

namespace noise
{
    namespace module
    {
        void ErosionModule::initDrop(unsigned int iterations)
        {
            for (int i = 0; i < iterations; i++)
            {
                Raindrop drop;
                drop.calculate();
            }
        }

        void ErosionModule::iterate(unsigned int iterations, unsigned int strength)
        {
            auto funcRef = &noise::module::ErosionModule::initDrop;

            funcRef(1000);
        }
    }
}

Help would be greatly appreciated

  • The syntax for calling a function using a pointer that points to a member function of a class is different than calling a function using a pointer that points to a non-member function. I am sure this has been asked in SO before. – R Sahu Feb 19 '21 at 17:28
  • Handy reading: [Pointers to Member Functions](https://isocpp.org/wiki/faq/pointers-to-members) – user4581301 Feb 19 '21 at 18:12
  • This is Just Another Microsoft Cock-up. A sensible compiler gives a helpful error message, such as (gcc compiler): "error: must use '.*' or '->*' to call pointer-to-member function in 'funcRef (...)', e.g. '(... ->* funcRef) (...)' ". – TonyK Feb 19 '21 at 18:18

1 Answers1

0

funcRef is a member pointer, use: (this->*funcRef)(1000);

Jan Kratochvil
  • 387
  • 3
  • 11