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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:55:20+00:00 2026-05-16T11:55:20+00:00

What the question says. In addition, is it possible to do this inline? Here

  • 0

What the question says. In addition, is it possible to do this inline?

Here is a small example just to give an idea…

template<typename T>
class Foo {
 public:
  Foo() :z(0.0) {}

  void do( const Foo<T> &f ) {
    z = f.z;
  }
  // specialize 'do' for Foo<int>, possible inline?

 private:
  T z;
};
  • 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-16T11:55:21+00:00Added an answer on May 16, 2026 at 11:55 am

    You can sort of get this behavior by making the member function a member function template and using SFINAE (substitution failure is not an error). For example:

    template <typename U>
    typename std::enable_if<!std::is_integral<U>::value && 
                            std::is_same<T, U>::value, void>::type
    f(const Foo<U>& x)
    {
    }
    
    template <typename U>
    typename std::enable_if<std::is_integral<U>::value && 
                            std::is_same<T, U>::value, void>::type
    f(const Foo<U>& x)
    {
    }
    

    The is_integral type trait test whether U is an integer type. If it is not, the first is instantiated; if it is, the second is instantiated.

    The is_same type trait tests to ensure T and U are the same type. This is used to ensure that the member function template is not instantiated for any type other than Foo<T>.

    This example makes use of the C++0x <type_traits> library; Boost also has a type traits library that you can use, which works mostly the same.

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

Sidebar

Related Questions

Question says it all but here is an example: typedef struct mutable_t{ int count,
The question says it all basically. I want in a class MyClass to listen
Question says it all. If I have this for a 96-bit field: uint32_t flags[3];
The question says it all, really. I know a (Scala) Monad looks like this:
As the title says. Related to this question. Why does the following code not
Question says it all - is there a class somewhere in Windows Forms that
the question says it all. Can someone please tell me if that is possible
As my question says, is there any possible way to send an email from
Just as the question says. I was curious because my development phone will also
Question says it all, should passwords be stored using 2 way encryption or just

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.