mardi 17 août 2021

How to solve the conflict between C++ enum and define

base.h is the basic library in my framework and cannot be modified.

// base.h
#ifndef OK
#define OK 0
#endif

grpc.h is the code segment of the open source framework.

// grpc.h
namespace grpc {
enum StatusCode { OK = 0 };
}

Could main.cc run without modifying the codes of base.h and grpc.h?

// main.cc
#include <iostream>
#include "base.h"
#include "grpc.h"
int main() {
  std::cout << "hello world\n";
  std::cout << grpc::StatusCode::OK;
  return 0;
}

Aucun commentaire:

Enregistrer un commentaire