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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:22:29+00:00 2026-06-01T19:22:29+00:00

Test.h #ifndef TEST_H #define TEST_H #include <memory> template <class Type> bool operator==(const std::weak_ptr<Type>& wp1,

  • 0

Test.h

#ifndef TEST_H
#define TEST_H

#include <memory>

template <class Type>
bool operator==(const std::weak_ptr<Type>& wp1, const std::weak_ptr<Type>& wp2)
{
std::shared_ptr<Type> sp1;

if(!wp1.expired())
    sp1 = wp1.lock();

std::shared_ptr<Type> sp2;

if(!wp2.expired())
    sp2 = wp2.lock();

return sp1 == sp2;
}

#endif

Test.cpp

#include "Test.h"
#include <list>


int main()
{
typedef std::list< std::weak_ptr<int> > intList;

std::shared_ptr<int> sp(new int(5));
std::weak_ptr<int> wp(sp);

intList myList;
myList.push_back(wp);

myList.remove(wp); //Problem
}

The program won’t compile due to myList.remove():

1>c:\program files (x86)\microsoft visual studio
10.0\vc\include\list(1194): error C2678: binary ‘==’ : no operator found which takes a left-hand operand of type
‘std::tr1::weak_ptr<_Ty>’ (or there is no acceptable conversion) 1>
with 1> [ 1> _Ty=int 1> ]

But you can see the following defined in Test.h:

bool operator==(const std::weak_ptr<Type>& wp1, const std::weak_ptr<Type>& wp2)

What is the problem?

  • 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-01T19:22:31+00:00Added an answer on June 1, 2026 at 7:22 pm

    The operator overload is found by argument-dependent lookup, and your function doesn’t apply as it’s not defined in namespace std (the namespace of the argument types, and the context of the expression inside std::list::remove).

    You should use remove_if to apply a custom predicate function. In general, don’t attempt to define operators for types inside libraries you cannot modify.

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

Sidebar

Related Questions

I have this definition for my Test class: #ifndef TEST_H #define TEST_H #include <iostream>
Got this in char.h #ifndef _CHAR_H_ #define _CHAR_H_ #include <stdio.h> template <unsigned int TChar>
I have a base class called Item : #ifndef ITEM_H #define ITEM_H #include <ostream>
Here's my header file Normal.h: #ifndef NORMAL_H #define NORMAL_H #include Vector3.h class Normal {
I've created a class with a boost::unordered_map as a member, Linkage.h #ifndef LINKAGE_H #define
Header file is graph.h #ifndef _GRAPH_H_ #define _GRAPH_H_ #include <map> #include <vector> using namespace
I have code with circular dependency. old a.h file: #ifndef A_H #define A_H #include
Everything was compiling until I added vector<Move> bestLine; search.h #ifndef SEARCH_H #define SEARCH_H #include
I have the following code: Master.h #ifndef MASTER_H #define MASTER_H class Master { friend
It seems like my two files, userinterface.h #ifndef USERINTERFACE_H #define USERINTERFACE_H #include <string> #include

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.