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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:42:07+00:00 2026-05-29T07:42:07+00:00

I have been using a template with an enum argument to provide specialised methods

  • 0

I have been using a template with an enum argument to provide specialised methods for output from my code.

template <Device::devEnum d>
struct sensorOutput;

template<>
struct sensorOutput <Device::DEVICE1>
{
    void setData(Objects& objs)
    {
        // output specific to DEVICE1
        // output velocity
        objs.set(VELOCITY, vel[Device::DEVICE1]);
        // output position
        objs.set(POSITION, pos[Device::DEVICE1]);
    }
};

template <>
struct sensorOutput <Device::DEVICE2>
{

    void setData()
    {
        // output specific to DEVICE2
        // output altitude
        objs.set(ALTITUDE, alt[Device::DEVICE2]);
    }
};

I now want add another sensor similar to DEVICE1 that will output velocity and position.

Is there a way of setting multiple specialisations? I have tried

template <>
struct sensorOutput <Device::DEVICE1 d>
struct sensorOutput <Device::DEVICE3 d>
{

    void setData()
    {
        // output specific to DEVICE1 and DEVICE3
        // output velocity
        objs.set(VELOCITY, vel[d]);
        // output position
        objs.set(POSITION, pos[d]);
    }
};
  • 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-29T07:42:07+00:00Added an answer on May 29, 2026 at 7:42 am

    How about inheritance?

    template<Device::devEnum d>
    struct sensorOutputVeloricyAndPosition
    {
        void setData()
        {
            // output specific to DEVICE1 and DEVICE3
            // output velocity
            objs.set(VELOCITY, vel[d]);
            // output position
            objs.set(POSITION, pos[d]);
        }
    }
    
    
    template<>
    struct sensorOutput<Device::DEVICE1> : public sensorOutputVeloricyAndPosition<Device::DEVICE1>
    { };
    
    template<>
    struct sensorOutput<Device::DEVICE3> : public sensorOutputVeloricyAndPosition<Device::DEVICE3>
    { };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A few test scenarios have been recorded using CodedUI test template for my web
I have been using PHP's DOM to load an html template, modify it and
I'm documenting code in Eclipse and have been using the /** followed by Enter
Here is the template that I have been using http://themes.truethemes.net/Karma-HTML/content-pricing-tables.html Here is my test
I have been using the DelegateCommand found in the MVVM Visual Studio template at
I have been working on a template using almost all jquery/javascript. Mostly I am
I have been using a custom template file called user-profile.tpl.php for a while. But
I have been using a variadic template that acts as an exception firewall in
I have been using the following code to redirect users to a domain for
I have been following this URL to help me create template views using BrowserView.

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.