Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9188389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:59:38+00:00 2026-06-17T19:59:38+00:00

I am using a library which defines its own set of errors as an

  • 0

I am using a library which defines its own set of errors as an enum type.

enum error_type {…}

The library also has a function which takes that enum type, and prints the error.

void set_status(error_type new_error)

If I want to define my own error, and give it to the set_status function, is it possible to extend the error_type enum somehow, or maybe override it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:59:39+00:00Added an answer on June 17, 2026 at 7:59 pm

    There might be some sharp edges, but I think this should work for you:

    #include<iostream>
    
    // Helper struct
    
    template<typename T, int N, typename... LIST>
    struct whereInType {
      static const int index = -1;
    };
    
    template<typename T, int N, typename HEAD, typename... TAIL>
    struct whereInType<T,N,HEAD,TAIL...> {
      static const int index = whereInType<T, N+1, TAIL...>::index;
    };
    
    template<typename T, int N, typename... TAIL>
    struct whereInType<T,N,T,TAIL...> {
      static const int index = N;
    };
    
    // The actual union type
    
    template<typename... ENUMS>
    class enum_union {
    public:
      template<typename ENUM>
      constexpr enum_union(ENUM val) :
        which_enum(whereInType<ENUM,0,ENUMS...>::index),
        value(val) {}
      constexpr operator long long(){
        return static_cast<long long>(which_enum)<<32 | value;
      }
      template<typename ENUM, int IGNORE=0>
      constexpr bool operator==(const ENUM& e) {
        return *this == enum_union<ENUMS...>(e);
      }
      template<int IGNORE=0>
      constexpr bool operator==(const enum_union<ENUMS...>& oth) {
        return which_enum==oth.which_enum && value==oth.value;
      }
      template<typename T>
      constexpr bool operator!=(const T& oth) {
        return !(*this == oth);
      }
    private:
      int which_enum;
      int value;
    };
    
    // An example usage
    
    enum normal_errors {
      E_OUTOFMEMORY,
      E_IOERROR
    };
    
    enum weird_errors {
      E_OUTOFAARDVARKS,
      E_DIVIDEBYCUCUMBER
    };
    
    typedef enum_union<normal_errors, weird_errors> any_error;
    
    // Some tests
    
    void print(any_error e) {
      switch(e) {
      case any_error(E_OUTOFMEMORY):
        std::cout << "Out of Memory\n";
        break;
      case any_error(E_IOERROR):
        std::cout << "I/O Error\n";
        break;
      case any_error(E_OUTOFAARDVARKS):
        std::cout << "WE NEED AARDVARKS!!!  NOW!!!!!\n";
        break;
      case any_error(E_DIVIDEBYCUCUMBER):
        std::cout << "please reinstall universe\n";
        break;
      }
    }  
    
    main(){
      print(E_OUTOFMEMORY);
      print(E_IOERROR);
      print(E_OUTOFAARDVARKS);
      print(E_DIVIDEBYCUCUMBER);
      if (any_error(E_OUTOFMEMORY) == E_OUTOFAARDVARKS) {
        std::cout<<"bad\n";
      }else{
        std::cout<<"good\n";
      }
      if (any_error(E_OUTOFMEMORY) != E_OUTOFAARDVARKS) {
        std::cout<<"good\n";
      }else{
        std::cout<<"bad\n";
      }
      if (any_error(E_OUTOFMEMORY) == E_OUTOFMEMORY) {
        std::cout<<"good\n";
      }else{
        std::cout<<"bad\n";
      }
      if (any_error(E_OUTOFMEMORY) != E_OUTOFMEMORY) {
        std::cout<<"bad\n";
      }else{
        std::cout<<"good\n";
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a third party library which has a blocking function, that is, it
I am using curl library which returns data to me through a callback function
I'm using a library which has both a C interface and a C++ interface
In my current project I am using a 3rd party library which has no
I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In
I'm using a library that defines some data type classes usually implemented as tight
I work with a library which defines its internal division operator for a scripting
According to MSDN Library using Statement (C# Reference) Defines a scope, outside of which
I am using the SFML library, which in its latest RC allows you to
I am using a networking library which uses a thread pool for delegating tasks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.