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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:38:35+00:00 2026-05-17T22:38:35+00:00

Say I have a templated class: template <typename T> class foo { void do_someting(T

  • 0

Say I have a templated class:

template <typename T>
class foo {
  void do_someting(T obj) {
    // do something generic...
  }
};

and I want to specialize do_something, but within it I want to call the “normal” do_something function:

template<>
void foo<MyObj>::do_something(MyObj obj) {
  // do something specific...
  // and ALSO do something generic!
}

is there a way to refer to the normal version of do_something within my specialized function? Or do I just have to copy the code?

(I know that I could refactor foo in such a way that I wouldn’t have this exact problem, but as it happens I can’t really modify the “real” foo, as it’s heavily-shared code.)

  • 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-05-17T22:38:36+00:00Added an answer on May 17, 2026 at 10:38 pm

    No. Your specialization is the only definition that will exist for the MyObj type argument. But, consider modifying the foo template in this manner, which will be transparent to the current users of the template:

    template<typename T>
    class foo {
      void prelude(T &obj){ // choose a better name
        /* do nothing */
      }
      void do_something(T obj){
        prelude(obj);
        // do something generic...
      }
    };
    

    Then define a specialization for the prelude:

    template<>
    void foo<MyObj>::prelude(MyObj &obj){
      // do something specific
    }
    

    This is somewhat similar in structure to the main use case for private virtual members. (Sort of. Not really. But it’s what inspired me in this answer.)

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

Sidebar

Related Questions

lets say i have a templated class template <typename T> struct Widget { //generalized
Lets say we have this code: class test_t { void* data; public: template <typename
I have a class template <typename Iterator, typename Value> class Foo { public: Foo(const
I have the following setup: A templated class SpecialModel: template<typename A, typename B> class
Say I have a template class that takes msgs from source, does something smart
Let's say I have this : class A { virtual int Method2(){/*...*/} }; template<typename
Let's say we have a class, MyParent: class MyParent { public: template<namespace T> MyParent()
Let's say you have a c++0x std::array member of a template class and you
Say you have a vector class that has a template length and type -
If I have a template class specification like so, template <typename T> class MyClass

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.