【问题标题】:GCC: sorry, unimplemented: mangling overloadGCC:抱歉,未实现:重载重载
【发布时间】:2011-11-22 06:36:45
【问题描述】:

我收到一段代码的编译错误(抱歉,未实现:重载),据我所知,这是正确的。我试图将代码最小化为一个易于管理的示例,但它仍然很长(对此感到抱歉)。我知道那里的 C++11 东西正在开发中,所以这可能是我的编译器(GCC 4.6.2)的问题,但也可能是我遗漏了一些东西。

mod 函数只是更复杂函数的占位符(具有不同的返回类型)。实际代码的目的是为一组数据结构提供索引,以便使用不同的匹配标准进行快速查找。

干杯
马库斯

#include <map>
#include <string>
#include <iostream>
#include <list>
#include <functional>
#include <cassert>

//
// Functions
//

struct mod2 : public std::unary_function<int, int> {
  int operator()(int x) const { return x % 2; }
};

struct mod3 : public std::unary_function<int, int> {
  int operator()(int x) const { return x % 3; }
};

struct mod4 : public std::unary_function<int, int> {
  int operator()(int x) const { return x % 4; }
};


//
// Base class foo
//

struct foo {
  std::vector<int> data_m;

  foo() : data_m() {}

  int& insert(int x) {
    data_m.push_back(x);
    return data_m.back();
  }

  template<typename trans_T>
  std::list<std::pair<typename trans_T::result_type, int> >
  match(const typename trans_T::result_type& pattern,
        const trans_T& trans = trans_T()) const {
    std::list<std::pair<typename trans_T::result_type, int> > results;
    for (auto it = data_m.begin(); it != data_m.end(); ++it) {
      auto p = trans(*it);
      if (pattern == p) {
        results.push_back(std::make_pair(p, *it));
      }
    }
    return results;
  }
};


//
// Derived class bar
//

template<typename base_T, typename trans_T>
struct bar : public base_T {
  typedef base_T base_type;
  typedef std::multimap<typename trans_T::result_type, int> index_type;
  index_type index_m;

  bar(const trans_T& trans = trans_T()) : base_type(), index_m() {}

  int& insert(int x, const trans_T& trans = trans_T()) {
    return index_m.insert(typename index_type::value_type(trans(x), base_type::insert(x)))->second;
  }

  std::pair<typename index_type::const_iterator,
            typename index_type::const_iterator>
  match(const typename trans_T::result_type& pattern,
        const trans_T& trans = trans_T()) const {
    return index_m.equal_range(pattern);
  }

  template<typename xtrans_T>
  decltype(base_type().match(typename xtrans_T::result_type(), xtrans_T()))
  match(const typename xtrans_T::result_type& pattern,
        const xtrans_T& xtrans = xtrans_T()) const {
    return base_type::match(pattern, xtrans);
  }

};


//
// Begin/end functions present in Boost but not in GCC
//

template<typename iter_T>
  iter_T begin(const std::pair<iter_T, iter_T>& range) {
  return range.first;
}

template<typename iter_T>
  iter_T end(const std::pair<iter_T, iter_T>& range) {
  return range.second;
}


//
// Main
//

int main(const int argc, const char** argv) {
  using std::cout;
  using std::endl;

  bar<bar<foo, mod2>, mod3> baz;


  ///
  /// Insert some numbers
  ///

  for (int i = 0; i < 20; ++i) {
    baz.insert(i);
  }

  for (int i = 0; i < 5; ++i) {
    cout << "i = " << i << endl;

    ///
    /// Try to match with different functions
    ///

    auto baz_match_mod2 = baz.match(i, mod2());
    cout << "mod2:";
    for (auto it = begin(baz_match_mod2); it != end(baz_match_mod2); ++it) {
      assert(it->first == i);
      cout << ' ' << it->second;
    }
    cout << endl;

    auto baz_match_mod3 = baz.match(i, mod3());
    cout << "mod3:";
    for (auto it = begin(baz_match_mod3); it != end(baz_match_mod3); ++it) {
      assert(it->first == i);
      cout << ' ' << it->second;
    }
    cout << endl;

    auto baz_match_mod4 = baz.match(i, mod4());
    cout << "mod4:";
    for (auto it = begin(baz_match_mod4); it != end(baz_match_mod4); ++it) {
      assert(it->first == i);
      cout << ' ' << it->second;
    }
    cout << endl;
  }

  return 0;
}

【问题讨论】:

  • 我建议在 gcc-help@gcc.gnu.org 上问这个问题
  • @n.m.:问题是:这是gcc的问题,还是我对c++的理解
  • @BasileStarynkevitch:谢谢。
  • sorry 表示已知的gcc 问题。

标签: c++ templates compiler-errors g++ c++11


【解决方案1】:

GCC 的错误消息仅在问题出在编译器而非您的代码时才使用短语“抱歉,未实现”——在这种情况下,您正在尝试使用尚未实现的 C++11 功能完全支持。

不幸的是,GCC 的网站不允许我 grep 获取该特定错误消息的代码,因此我无法帮助您准确找出未实现的内容。我赞同 Basile 的建议,可以在 gcc-help@gcc.gnu.org 上提问。

【讨论】:

  • 谢谢,我确实采纳了 Basile 的建议,并从 gcc 的人那里得到了相同的答案。我想我没有足够的信心假设编译器有问题。 :-)
猜你喜欢
  • 2012-02-10
  • 2014-03-07
  • 2021-07-15
  • 2014-11-07
  • 2012-10-19
  • 1970-01-01
  • 1970-01-01
  • 2013-02-28
  • 2019-05-08
相关资源
最近更新 更多