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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:36:55+00:00 2026-06-17T01:36:55+00:00

Here it goes: I want to create a void function that will receive two

  • 0

Here it goes: I want to create a void function that will receive two well-known type of values and another one that could be anything. The code would be like this:

void change_settings(string element, short setting, ??? value) {
    switch (setting) {
        case ST_NAME:
            // Cast value to string or char* and change element.name
        break;
        case ST_AMOUNT:
            // Cast value to integer and change element.amount
        break;
        case ST_ENABLED:
            // Cast value to boolean and change element.enabled
        break;
    }
}

I tryied to make the value’s type const void* but I get an error (cast from ‘const void*’ to ‘short int’ loses precision) because I just did this: short name = (short)value, which must be some crazy desperate trial, hoping to get lucky. Now, I don’t know if there’s a way of doing this, pass the pointer of whatever kind of variable then convert it to what it is (I know the type of variable to expect depending on each case.
How would I do this? Thanks!

  • 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-17T01:36:56+00:00Added an answer on June 17, 2026 at 1:36 am

    Since you seem to know in advance all the potential types of value, and you want different behavior depending on the type, you can just write a series of function overloads:

    void change_settings(const std::string& element, short setting, const std::string& value);
    
    void change_settings(const std::string& element, short setting, int value);
    
    void change_settings(const std::string& element, short setting, bool value);
    

    This eliminates the need for a run-time switch.

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

Sidebar

Related Questions

Ok, first question so here goes, A function that runs on activation of a
Alright, here goes. I'm making a very basic app, and I want the user
<?php while(true){ //code goes here..... } ?> I want to make a PHP web
I have a list that contains FrameworkElements and I want to create an extension
I want to retrieve token via Account Manager classes. Here is sample code that
I want to have a tooltip that shows different things when the mouse goes
I have a Java Swing application that i want to create a nice component
I want to create a utility method that creates an IObservable for an Action
Ok here goes: I have a SELECT drop down option with US state names
Ok here goes. This is my first ever wicket application and I'm trying to

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.