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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:44:52+00:00 2026-05-15T10:44:52+00:00

I have a set data type: template <class V> struct Set { void add(const

  • 0

I have a “set” data type:

template <class V>
struct Set {
  void add(const V& value) {}
};

I want to write a top-level function version of Set::add.

template <class V>
void add(const Set<V>& set, const V& value) {}

This doesn’t quite work with string literals:

Set<const char*> set;
const char* val = "a";

set.add(val); // ok
set.add("a"); // ok

add(set, val); // ok
add(set, "a"); // ERROR
add<const char*>(set, "a"); // ok

The error message (g++ 4.2.4):

no matching function for call to ‘add(Set<const char*>&, const char [2])’

It looks it has something to do with the fact that "a" has type const char[2] and not const char*. Does anybody know how to get this to work?

  • 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-15T10:44:53+00:00Added an answer on May 15, 2026 at 10:44 am

    The problem is that V gets one type for the left parameter, and another type for the right one. I suspect you also want to be able to say add(setOfLong, 0) – but with that template you couldn’t. I recommend to add a separate template parameter to solve this

    template <class SetV, class V>
    void add(const Set<SetV>& set, const V& value) {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer you have a typo on searchable_by *_column_names should be *column_names,… May 16, 2026 at 12:39 pm
  • Editorial Team
    Editorial Team added an answer I lead the EclipseLink JAXB & SDO implementations and represent… May 16, 2026 at 12:39 pm
  • Editorial Team
    Editorial Team added an answer It's not quite as simple as pavel's answer states, because… May 16, 2026 at 12:39 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a template class where I want to use objects of that class
I want to add a operator override to perform assignments /__set__s inline. Template :-
In a moment of madness, I decided to write a quadtree C++ template class.
Given a functor appropriate for use with std::for_each and friends: template <typename T> struct
Given the following template: template <typename T> class wrapper : public T {}; What
I am trying to add Series binding to the Visifire graphing controls set. To
I have a scenario where I have a list of classes, and I want
I wrote a sparse vector class (see #1 , #2 .) I would like
EDIT -- Answered below, missed the angled braces. Thanks all. I have been attempting
So here is the XAML that I have: <ItemsControl ItemsSource={Binding Path=Groups} ItemTemplateSelector={Binding RelativeSource={RelativeSource AncestorType=Window},

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.