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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:27:04+00:00 2026-05-30T23:27:04+00:00

I have a template member function of a class that I’m using for adding

  • 0

I have a template member function of a class that I’m using for adding various different types to a list, with special handling and wrapping (everything ends up wrapped in a var object) for specific types:

template<typename V> const var& addvar(const V& v);

template<> const var& addvar<std::string>(const std::string& v) {/*stuff*/}

However, I’m passing around strings (well, const char arrays) like this to it:

object.addvar("lol");

Although I’m handling everything as std::strings, this pops in as some sort of const char array reference in the template parameter type deduction. So I get an error about not having a function for it, even with the above std::string specialization. I’m familiar with template array size deduction, so I’m trying to use that format to create an addvar that can handle such a thing, something like:

template<size_t N> const var& addvar<char>(const char& (&v)[N]) {/*stuff*/}

But things are going horribly with compiler errors about illegal arrays of references. This is in VC++ 2010, if there’s any specific weirdness with that, but I get the feeling I’m messing up something fundamental here.

  • 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-30T23:27:06+00:00Added an answer on May 30, 2026 at 11:27 pm

    You can’t partially specialize template function, so it has to be an overload (= a template that doesn’t share anything with the initial addvar template function):

    template<size_t N> const var& addvar(const char (&v)[N]) {/*stuff*/}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a template class that has a template member function that needs to
Lets say you have simple template function (not class member for the sake of
I have a problem with class member function templates. It seems that gcc is
I have a member function of a template class declared as such: template <class
I have a templated class with an templated member function template<class T> class A
I have a class template Foo<T> . I'd like to implement a non-member function
I got trouble in creating special instance of member template function of non-template class.
I wonder if it is a good practice to have a member template function
I have template function compare defined as below. #include<iostream> using namespace std; template<typename T>
I have a template class that I serialize (call it C), for which I

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.