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 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 how I could simplify this code, without using
I'm getting this error with this javascript can anyone help me figure out what
Nothing I've tried can get my code to submit correctly. Can anyone else figure
Can anyone figure out what's going on here? I was able to get my
can anyone figure out why the h:outputText doesn't get refreshed after inputText value change?
Can anyone explain how compilation works? I can't seem to figure out how compilation
This is a bit of a long shot, but if anyone can figure it
Can anyone help me? I can't figure out what I am doing wrong but
I need to solve the following question which i can't get to work by
I am a beginner in mootools, can anyone help me figure out how to

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.