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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:00:48+00:00 2026-05-24T22:00:48+00:00

My goal is to access a class that is passed in as a parameter

  • 0

My goal is to access a class that is passed in as a parameter inside of myFunction.

Here’s what I’m trying to do:

void myFunction(string myString)
{
   callFunctionOn(OuterType::InnerType::myString);
}

I’m trying to call some function on something that’s in a type. For example, my code in some other file might look like:

namespace OuterType {
namespace InnerType {
//stuff here
}
}

However, using myString in that way doesn’t work. If myString holds the value “class1”, then I want that callFunctionOn part to be interpreted as

callFunctionOn(OuterType::InnerType::class1);

I feel like this is super simple, but I’ve been programming all day and my mind grows tired…

SOLVED: It looks like in order to this in this way, I’d need a language with reflection. To solve this I took a different approach to the problem and passed in a pointer to the class instead.

  • 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-24T22:00:49+00:00Added an answer on May 24, 2026 at 10:00 pm

    C++ doesn’t have reflection built in, but it does have pointers to data, functions, and class members. So you can use a std::map or unordered_set to find the pointer with a particular name (you have to add all the name/pointer pairs into the map beforehand).

    Your solution is likely to look something like:

    namespace Outer
    {
        namespace Inner
        {
            void funcA( void ) { std::cout << "called funcA" << std::endl; }
    
            std::map< std::string, void (*)(void) > members;
        }
    }
    
    // in some initialization function
    Outer::Inner::members["funcA"] = &Outer::Inner::funcA;
    
    
    // later
    std::string myString = "funcA";
    void (*f)(void) = Outer::Inner::members[myString]; // lookup function by name
    (*f)(); // call function via its pointer
    

    Of course the type of the pointer will probably need to change to meet your application requirements.

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

Sidebar

Related Questions

I'm trying to access a property of an object inside a method of that
I have a project here the goal is to merge multiple Access DB's into
I have a class that I am trying to do unit tests on. The
Goal : My intention to design a utility that could access any numeric values(
I'm trying to build an object that looks something like this: public class MyObject
My goal is to access the byte[] representing the bytecode of a class without
The goal is to access the nth element of a vector of strings instead
Goal: to programmatically determine the sizes (in bytes) of the fields of a class.
goal: I have the string 1234432144 I want to only replace the first 2
My goal here is to create a very simple template language. At the moment,

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.