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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:20:28+00:00 2026-06-04T15:20:28+00:00

Using MSVC 2010, I get the following behaviour: template <class T> class Boogy {

  • 0

Using MSVC 2010, I get the following behaviour:

template <class T> class Boogy
{
public:
    void Fn( T in )
    {
    }

    void Fn2( const T& in)
    {
    }
};

template <> void Boogy<int>::Fn( int in ) //builds ok
{
}

template <> void Boogy<int*>::Fn( int* in ) //builds ok
{
}

template <> void Boogy<int>::Fn2( const int& in ) //builds ok
{
}

template <> void Boogy<int*>::Fn2( const int*& in ) //DOES NOT BUILD
{
}

typedef int* intStar;
template <> void Boogy<intStar>::Fn2( const intStar& in ) //builds ok
{
}

Obviously, I’ve come up with a ‘hack’ to sort my issue out, but why is the hack necessary? And should we be doing this at all? The code base I’m in has dozens of instances where template classes have SOME specialisations of SOME of the member functions – not of the whole class. A colleague is adamant that this isn’t allowed.

TIA.

  • 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-04T15:20:30+00:00Added an answer on June 4, 2026 at 3:20 pm

    It should be int * const &. You have T = int *, so const T = T const = int * const.

    Remember that U const & means “reference to constant U“, and not “constant reference to U” — the latter doesn’t make sense, since reference variables in C++ are always constant, i.e. cannot be reseated. In your case the U is a pointer-to-int, and not a pointer-to-const-int, which are two different types.

    You can of course also add a separate specialization for int const *:

    template <> void Boogy<int const *>::Fn2(int const * const & in) { /* ... */ }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iostream> #include <boost/shared_ptr.hpp> using namespace std; class A { public: const shared_ptr<const int>
Header class linkNode { public: linkNode(void *p) { before = 0; after = 0;
I'm trying to build Boost 1.49.0 using MSVC2010 and it fails with the following
I am trying to build a program using the command scons compiler = msvc.
Using LINQ on collections, what is the difference between the following lines of code?
I am trying to compile Flusspferd on Windows using MSVC, but it fails due
How come this code std::map <std::string , int> m; m[a]=1; compiles with (I'm using
I'm using MSVC and it seems like the code below does not crash and
I am using MSVC 6.0 to call a macro in the Win32API and I'm
I'm using QtCreator on windows using MSVC compiler (the compiler from Visual c++ express

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.