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 841517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:48:31+00:00 2026-05-15T05:48:31+00:00

I get the following error with VS2008: Conversion to enumeration type requires an explicit

  • 0

I get the following error with VS2008: Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)

When casting a down casting a ClassA to ClassA_1 and ClassA_1 is a templated class that received an enum for parameter such as:

THIS IS AN EDIT OF MY QUESTION WHICH RE-USE AN ANSWER BELOW BUT MODIFED TO CAUSE THE PROBLEM I AM HAVING, here we go:

Ok i have been able to reproduce my error with this code:

class ClassA
{
public:
    virtual ~ClassA(){}
};

template <class Param1 = void*> class ClassB : public ClassA {
public:
    //constructor
    ClassB(Param1 p1 = NULL)
    {
        _p1 = p1;
    }
    //ClassB(const ClassB<Param1>& ref);
    Param1 _p1;
    ~ClassB(){}
};

enum lolcakes {
    cakeisalie,
};


ClassA* ptr = new ClassB<lolcakes>(lolcakes::cakeisalie);

ClassB<lolcakes>* a1 = (ClassB<lolcakes>*)ptr;
  • 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-05-15T05:48:32+00:00Added an answer on May 15, 2026 at 5:48 am

    There are so many syntax errors here, I don’t know where to begin. Next time, please post the actual code you used.

    For starters, I’m assuming that you meant to write this:

    ClassA<myenum>* a = new ClassA_1<myenum>();
    

    In other words, a is a pointer and its type is ClassA<myenum>*, not merely ClassA (and we’ll ignore the missing argument to the constructor).

    Now, your cast syntax is wrong in both cases. The parentheses need to go around the type only. But better use a static_cast anyway:

    ClassA_1<myenum>* a1 = static_cast<ClassA_1<myenum>*>(a);
    

    This works.

    UPDATE After question edit:

    The important error is in this line:

    ClassB(Param1 p1 = NULL)
    

    you cannot use NULL as the default parameter since your Param1 type is not a pointer – it’s an enum (strictly speaking this should work since NULL is defined as being equal to 0 in C++, but it’s a logical error nonetheless). Instead of making the parameter optional, a better alternative would be to overload the constructor. Alternatively, the following also works:

    ClassB(Param1 p1 = Param1())
    

    This uses the default value for the type Param1.

    There’s an additional error in the code:

    ClassA* ptr = new ClassB<lolcakes>(lolcakes::cakeisalie);
    

    Enum constants don’t work like that in C++: They don’t create an own namespace, hence their usage cannot be qualified. Instead, omit the enum’s name:

    ClassA* ptr = new ClassB<lolcakes>(cakeisalie);
    

    Finally, please don’t use C-style casts, ever. Always replace them with the appropriate C++-style casts. In your case, replace

    ClassB<lolcakes>* a1 = (ClassB<lolcakes>*)ptr;
    

    with

    ClassB<lolcakes>* a1 = boost::polymorphic_downcast<ClassB<lolcakes>*>(ptr);
    // or
    ClassB<lolcakes>* a1 = static_cast<ClassB<lolcakes>*>(ptr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 431k
  • Answers 431k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Because the second cout will print what is pointed by… May 15, 2026 at 2:16 pm
  • Editorial Team
    Editorial Team added an answer Unfortunately the only way I can find to do this… May 15, 2026 at 2:16 pm
  • Editorial Team
    Editorial Team added an answer It depends on what kind of space you are trying… May 15, 2026 at 2:16 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.