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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:57:38+00:00 2026-06-15T05:57:38+00:00

I’m writing an interpreter for a simple, Lisp-like programming language. It will process the

  • 0

I’m writing an interpreter for a simple, Lisp-like programming language. It will process the code into nodes, all of them have types and some of them may have child nodes in an indexed order. Because of the difference in the nature of information, I can’t use the same length of type for all node values. The name of their type is an enum type, but the only idea I have for the type of values is void *. But when I use this, I must be very careful, I think. I mean, I can’t use any default destructors, I must write a destructor that cares about the node type. Also I would have to use lots of casts even to access values.

This is what I’m talking about:

enum NodeType {/* Some node types */}

class Node
{
public:
    Node(string input_code);
private:
    NodeType type; // Having this I can know the type of value
    void* value;
};

Is there a way that is more secure, makes a better code but is still as efficient as usage of void pointers?

  • 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-15T05:57:40+00:00Added an answer on June 15, 2026 at 5:57 am

    There are two options I can think of. One is to use polymorphism, in which you have an abstract base class, Node and a number of type-specific subclasses. Perhaps something like:

    class Node
    {
    public:
      virtual ~Node() = 0;
    };
    
    class String : public Node
    {
    public:
      ~String() {}
    };
    
    class Float : public Node
    {
    public:
      ~Float() {}
    };
    

    When storing these nodes, you would store Node* rather than void*. The presence of the (abstract) virtual destructor in the base class makes it possible to properly destroy concrete objects via the base class pointer, as with:

    Node* obj = new String;
    delete obj;
    

    You can also call methods declared in the base class and have them execute code in the correct derived class, if those methods are virtual in the base class. these will often also be pure virtuals, such as with:

    class Node
    {
    public:
      std::string Speak() const = 0; // pure virt
    };
    
    class String : public Node
    {
    public:
      std::string Speak() const { return "Hello"; }
    };
    

    Another option is to use some kind of variant class. C++ itself has no variant class built in to the language, but some libraries have been written such as Boost, which provide such a class.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.