小编use*_*486的帖子

模板化继承中的范围解析(可能称为mixin)

假设我有模板化的类

#include <iostream>

class A1 {
public:
  int x{314159};
};

template<typename Context>
class A2 : public Context {};

template<typename Context>
class A3 : public Context {};

template<typename Context>
class A4 : public Context {
public:
  int func() {
    return Context::A1::x;
  }

  int gunc() {
    return this->A1::x;
  }

  int hunc() {
    return A1::x;
  }
};

int main() {
  A4<A3<A2<A1>>> my_A;

  std::cout << "x = func() = " << my_A.func() << std::endl;
  std::cout << "x = gunc() = " << my_A.gunc() << …
Run Code Online (Sandbox Code Playgroud)

c++ templates scope-resolution

6
推荐指数
1
解决办法
126
查看次数

标签 统计

c++ ×1

scope-resolution ×1

templates ×1