c ++模板函数指针

时间:2018-07-18 02:01:23

标签: c++ templates

我遇到了c ++模板函数伪造问题,请帮忙。非常感谢。

    if (cursor.moveToFirst())
    {
        while (!cursor.moveToNext())
        {
            balance = cursor.getFloat(cursor.getColumnIndex(DatabaseContract.Database.COLUMN_BALANCE));
            voucher = cursor.getInt(cursor.getColumnIndex(DatabaseContract.Database.COLUMN_VOUCHER));
        }
    } else
    {

        Log.d(TAG, "Cursor count is " + String.valueOf(cursor.getCount()));
    }

符合:clang ++ -std = c ++ 11 -o c c.cc

错误:

class AAA {
  public:
    template<typename K>
    void dooo(K str) {
      std::cout << str << std::endl;
    }
};

template<typename Class, typename ret, typename K>
using Func = ret (Class::*) (K);

int main() {
  Func<AAA, void, int> myFunc = &AAA::dooo;

  myFunc(3);

  return 0;
}

1 个答案:

答案 0 :(得分:4)

由于dooo()不是static的{​​{1}}成员函数,因此您需要AAA的实例才能在以下位置调用AAA

myFunc