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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:18:14+00:00 2026-06-10T14:18:14+00:00

I have a base class IStructure which is derived by many classes. Some of

  • 0

I have a base class IStructure which is derived by many classes.

Some of these classes ‘reference’ other IStructure classes. For example, my class class GuiButton : public IStructure has a member of Textstring (which derives from IStructure, as well).

Now I’m just glistening over this so I can get to the point, so this may seem weird to some of you. I would like to have a template class ‘Reference’ that references an IStructure. For example:

class GuiButton : public IStructure {
public:
    Reference<Textstring> Text;
};

I know some of you might be wondering why I just don’t do Textstring* Text. This is because some of these references are “external”. The Reference template class only holds information about the IStructure (ie. Name, etc.). Some of these classes are insanely big and it would be pointless to instantiate that whole class to only use the Name property and what not. Does that make sense?

So now to my question:

class Textstring : public IStructure;

I can reference a Textstring by using my template:

Reference<Textstring> Text;

Now here’s the issue: Some methods I have require me to upcast to `IStructure’, for example:

void RegisterReference(Reference<IStructure> &reference);

So I couldn’t do this:

Reference<Textstring> txt("TextName");
RegisterReference(txt); // error

I know I can cure this by not having Reference be a template, but I would really like to because it makes it easier to understand and know what type the reference is.

What are some ways I can accomplish this?

Thanks for your help!

-Alex

  • 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-10T14:18:16+00:00Added an answer on June 10, 2026 at 2:18 pm

    You can make your function a template on the type parameter of the Reference, like this:

    template <typename R>
    void RegisterReference(Reference<R> &r);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have base class BaseClass and derived classes DerivedA , DerivedB , and DerivedC
I have a base class with many sub-classes, and a generic function to cache
I have a set of classes which are all derived from a common base
So say, for example I have two classes: Base = declarative_base() class Vendor(Base): __tablename__
I have a base class: class motorcycle { public: virtual int speed() { return
I have a base class like this: public class BaseResponse { public string ErrorMessage
I have a base class called Panel, where some information about a window is
I have a base DLL which defines some basic structure and operation for a
Say I have an abstract class Base, of which another abstract class Subclass extends.
I have a structure of base class and a couple of inherited classed. Base

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.