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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:11:44+00:00 2026-05-11T09:11:44+00:00

Can anyone figure out a nice way to get the following code to work?

  • 0

Can anyone figure out a nice way to get the following code to work? (This is, once again, an incredibly simplified way of doing this)

template <class f, class g> class Ptr;

class RealBase { };

template <class a, class b, class c = Ptr<a,b> > class Base : public RealBase { public: Base(){}; };

template <class d, class e> class Derived : public Base <d,e> { public: Derived(){}; void DerivedMethod(){}; }; template <class f, class g> class Ptr { public: Ptr(){}; Ptr(Base<f,g,Ptr<f,g> >* a){in = a;}; Base<f,g,Ptr<f,g> >* operator->() { return in; }; private: Base<f,g,Ptr<f,g> >* in; };

typedef Derived<double,double> DDerived;

int main() { Base<int,int> b = Base<int,int>(); Derived<double,double> d = Derived<double,double>(); DDerived dd = DDerived(); Ptr<double,double> p(&dd); p->DerivedMethod(); return 1; }

At the moment the compiler moans because a Base<> doesn't have a DerivedMethod();

EDIT

I do understand the problem here, my bad for a lack of explanation in the first case (I was in a rush). [This is very cut down code by the way so, yes, for the sake of simplicity I don't have destructors or methods that actually DO anything. Just ignore that, it makes no difference to the problem.]

What I need to happen is that an iterator (that isn't detailed here) that deals only with the derived class (D_Derived) need to access a method that is contained within a derived class and not the base class. Simply plonking this method into the base class isn't really an option because this error is going to occur a LOT if I have to do that. (There are about 10 classes built on the real base class, and they all have derived methods of their own. Like 20 of them. Each.)

Can anyone think of another way to achieve this functionality?

  • 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. 2026-05-11T09:11:45+00:00Added an answer on May 11, 2026 at 9:11 am

    OK. After trying about 10 different methods (static_cast, reinterpret_cast etc.) you can just cast it.

    int main() {     Base&lt;int,int> b = Base&lt;int,int>();     Derived&lt;double,double> d = Derived&lt;double,double>();     DDerived dd = DDerived();     Ptr&lt;double,double> p(&dd);     DDerived * fauxpointer;     fauxpointer = (DDerived\*) &(*p);     fauxpointer->DerivedMethod();     return 1; } 

    Nasty. But it works, and that’s all that counts.

    Cheers to everyone who repeated the question back at me.

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

Sidebar

Related Questions

Can anyone help me figure out whats wrong with this piece of xaml code?
I almost figure this out, can anyone tell me as to why my $.unblock
can anyone figure out why the h:outputText doesn't get refreshed after inputText value change?
Can anyone figure out why this will double the first result in the array?
Can anyone tell me why this code would not be working? $('body').on('test', function() {
This is really bugging me and I can't figure it out. I have a
Can anyone explain how compilation works? I can't seem to figure out how compilation
Can anyone help, i trying to figure what i need to do, i have
Can anyone enlighten me to a way I can Highlight the content of an
Can anyone explain to me why this program: for(float i = -1; i <

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.