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

  • Home
  • SEARCH
  • 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 7185253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:22:30+00:00 2026-05-28T18:22:30+00:00

When passing forward declared struct or a class, one has to pass it to

  • 0

When passing forward declared struct or a class, one has to pass it to a function through a reference or a pointer.

But, what can be done with a forward declared enum? Does it also have to be passed through a reference or a pointer? Or, can it be passed with a value?

Next example compiles fine using g++ 4.6.1 :

#include <iostream>

enum class E;

void foo( const E e );


enum class E
{
  V1,
  V2
};

void foo( const E e )
{
  switch ( e )
  {
    case E::V1 :
      std::cout << "V1"<<std::endl;
      break;
    case E::V2 :
      std::cout << "V2"<<std::endl;
      break;
    default:
      ;
  }
}

int main()
{
  foo( E::V1);
  foo( E::V2);
}

To build :

g++ gy.cpp -Wall -Wextra -pedantic -std=c++0x -O3

Is the above standard compliant, or is it using an extension?

  • 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-28T18:22:32+00:00Added an answer on May 28, 2026 at 6:22 pm

    A declared enum, even if you don’t specify the enumerators (what the standard calls an opaque-enum-declaration) is a complete type, so it can be used everywhere.

    For completeness, here’s a quote from paragraph 3 of §7.2:

    An opaque-enum-declaration is either a redeclaration of an enumeration
    in the current scope or a declaration of a new enumeration. [Note: An
    enumeration declared by an opaque-enum-declaration has fixed
    underlying type and is a complete type. The list of enumerators can be
    provided in a later redeclaration with an enum-specifier. —end note ]

    And the grammar for opaque-enum-declaration, from paragraph one of the same §7.2:

    opaque-enum-declaration:

    enum-key attribute-specifier-seqopt identifier enum-baseopt;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm passing a reference of a form to a class. Within this class I
Shaders can not read data from framebuffer, they can pass data only forward by
There is a forward C struct declared in an unmodifiable header. I would like
Passing an undimensioned array to the VB6's Ubound function will cause an error, so
warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast and
When you're passing variables through your site using GET requests, do you validate (regular
I'm currently passing the pid on the command line to the child, but is
Is it possible to forward a request, passing along all GET/POST params? I think
I'm not sure why, but I'm having trouble passing a data object (NSManagedObject) to
Occasionaly I find that I need a generic pass through-interface. For example for mix-in

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.