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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:25:19+00:00 2026-06-14T23:25:19+00:00

Given a base class, that contains the public static method with the general logic

  • 0

Given a base class, that contains the public static method with the general logic for all the derived classes (such as creating them). Parametrizing types of child class template are passed to the base class template (along with the type of the child class in order to have access to its custom static methods in the static method of the base class). From combinations of these types are typedefed new “types” (this is done in the base class to avoid a duplication of some code). They then re-typedefed (similar) in public sections of derived classes. I would use these type definitions into the class containing the helpers, as follows:

#include <iostream>
#include <vector>

#include <cmath>
#include <cstdlib>

template< class DERIVED >
class HELPERS;

template< class V, class DERIVED >
struct BASE
{

    typedef typename V::value_type F;

    static
    F some_common_operation()
    {
        return helpers.approximate_x(DERIVED::value()); // some common logic (HELPERS::approximate_x() here) depending on the value of DERIVED::value()
    }

    static
    DERIVED create_biased(F const & x)
    {
        return DERIVED(F(0.5) * (x + some_common_operation()));
    }

protected :

    BASE(F const & x_)
        : x(x_)
    { ; }

    F x;

private :

    static
    HELPERS< DERIVED > const helpers;

};

template< class V, class DERIVED >
HELPERS< DERIVED > const BASE< V, DERIVED >::helpers;

template< class V >
class DERIVED
    : public BASE< V, DERIVED< V > >
{

    typedef BASE< V, DERIVED< V > > B;
    friend B;

public :

    typedef typename B::F F;

    DERIVED(F const & x_)
        : B(x_)
    { ; }

    F shape(F const & y) const
    {
        return y * x;
    }

private :

    static constexpr
    F value()
    {
        return F(2.0L); // custom data
    }

    using B::x;

};

// template< class > class DERIVED1;...

template< class D >
struct HELPERS // set of helpers, that operates on classes derived from BASE
{

    typedef typename D::F F; // error: no type named <F> in <class DERIVED<std::vector<double> >>

    F approximate_x(F const & x) const
    {
        using std::sqrt;
        return sqrt(x);
    }

};

int main()
{
    DERIVED< std::vector< double > > d(2.0L);
    return EXIT_SUCCESS;
}

I’m trying to get the definition in the helpers class, but I get an error (g++ -std=gnu++11 a.cpp).

a.cpp: In instantiation of «struct HELPERS<DERIVED<std::vector<double> > >»:
a.cpp:44:26: required from «struct BASE<std::vector<double>, DERIVED<std::vector<double> > >»
a.cpp:47:7: required from «class DERIVED<std::vector<double> >»
a.cpp:97:39: required from here
a.cpp:85:27: error: no type named «F» in «class DERIVED<std::vector<double> >»

What is wrong? Typedef and all its “ancestors” are accessible (placed in public sections) in the chain of classes.

  • 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-14T23:25:20+00:00Added an answer on June 14, 2026 at 11:25 pm

    This is a chicken egg problem.

    It is happening because at the time you define BASE, DERIVED is not fully defined yet (because the compiler needs to resolve the base class first). Hence, you can’t access any typedefs of DERIVED in HELPER. To make sure you can check the following is not working as well:

    template< class V, class DERIVED >
    struct BASE
    {
        typedef typename V::value_type F;
        typedef typename DERIVED::F G; // <-- error here
        ...
    }
    

    What you can try is move the use of HELPER to DERIVED, or use V as the parameter for HELPER.

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

Sidebar

Related Questions

Given a base class with the following interface: public class Base { public virtual
In other words, given a base class shape and a derived class rectangle :
Given the sample code: class Base { public: bool pub; protected: bool prot; };
Given an existing code base being used in production containing a class A that
say your given an instance of List[Class[_ <: Base]] , and say that many
I have a Fleet class that contains an array of (base class) Vehicles. The
I have a base class which contains an abstract/MustInherit method. I want this method
given a Python class hierarchy, say class Base: def method1 def method2 def method3
Given this class: class MyModel < ActiveRecord::Base belongs_to :association1 belongs_to :association2, :polymorphic => true
Given the following models: team.rb class Team < ActiveRecord::Base has_many :events, :dependent => :destroy

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.