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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:33:49+00:00 2026-06-09T10:33:49+00:00

I am implementing something similar to a typed genetic programming and have become a

  • 0

I am implementing something similar to a typed genetic programming and have become a little stuck with regards to C++ types.

I have a network of nodes, nodes have different types, for example some are functional nodes whereas others are just data. In order to deal with collections of such nodes, I saw no option other than to use polymoprphism to store colection of base class pointers.

class Node {
private:
    std::string label;
    std::string node_type;
};

template
<typename FNC>
class FunctionalNode : public Node {
    std::function<FNC> function;
};

class Network {
   std::vector<Node*> nodes;
   ...
}

Note I have a templated FunctionalNode, which stores a std::function, I think (but am not certain) that my problem applies equally if I were to store a plain function pointer instead.

So the problem is, at some point given a Node pointer to a dervied FunctionalNode, I need to apply the stored function to some values. This means I need to cast the base pointer onto the derived class, but since it is templated I am not sure how to do this.

I would like to do something like the following fake C++ code, which would need something like type variables:

Node * applyfunction(Node * functional_node, std::vector<Node*> arguments) {
    typevariable function_type = convert_node_type_to_typevariable(functional_node.node_type)
    functional_node_derived * = static_cast<function_type>(functional_node);
    ....
}

Where a node’s node_type is some structure I use to contain the type information of the node, e.g. the type of its functional form, and convert_node_type_to_typevariable would convert this to a typevariable I can use in this hypothetical C++ language.

Any ideas how I could implementing this seing as C++ lacks support for type variables, or a completely different approach to the problem?

  • 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-09T10:33:50+00:00Added an answer on June 9, 2026 at 10:33 am

    You should exploit your polymorphic structure. You can define Node with a pure virtual method instead of making applyfunction a free function.

    class Node {
    protected:
        std::string label;
        std::string node_type;
    public:
        virtual ~Node () {}
        virtual Node * applyfunction (std::vector<Node *> args) = 0;
    };
    

    Then your derivations would perform the work.

    template
    <typename FNC>
    class FunctionalNode : public Node {
        std::function<FNC> function;
    public:
        Node * applyfunction (std::vector<Node *> args) {
            //...
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm looking into implementing something similar to the li's in chrome extension page .
I am currently implementing something similar to an hospital intra site, where doctors can
Just wondering how you would go about implementing something similar to stackoverflow'd related questions.
I having some problems implementing IOC using windsor. I have several different implementations of
I think I know C++ reasonably well and I am thinking about implementing something
I might be missing something obvious here, but I'm implementing NSCopying on one of
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I want to do something similar to http://www.mailhooks.com/ . When a email is received,
If I could find a way to do something similar to this, I could
inspired by Clojure, and Peter Norvig I have been trying my hand at implementing

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.