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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:10:10+00:00 2026-06-18T11:10:10+00:00

I’m sure I’m doing something stupid here, but I can’t see it. Why doesn’t

  • 0

I’m sure I’m doing something stupid here, but I can’t see it. Why doesn’t the following compile?

#include <algorithm>
#include <memory>
#include <vector>
#include <string>

// A class to play with.  Encapsulates a name.
class StringClass
{
public:
    StringClass(std::string const & name) : MyName(name) 
    {
    }

    std::string const & Name() const
    {
        return MyName;
    }

private:
    std::string MyName;
};

// The set of instances of "StringClass".

std::vector<std::shared_ptr<StringClass>> MyInstances;

// Function returns "true" if a class with the given name exists in the collection.
bool Exists(std::string const & name)
{
    auto i = std::find(MyInstances.begin(), MyInstances.end(), [&](std::shared_ptr<StringClass> const & instance) {
        return instance->Name() == name;
    });

    return i != MyInstances.end();
}

I’ve made a vector of shared_ptr to a class. The class has a Name() property. All I want to do is iterate the vector looking for an instance of the class with the given name. However, it doesn’t compile :(.

Errors are:

1>ClCompile: 1> test.cpp 1>c:\program files (x86)\microsoft visual
studio 10.0\vc\include\algorithm(41): error C2679: binary ‘==’ : no
operator found which takes a right-hand operand of type ‘const
anonymous-namespace'::<lambda0>' (or there is no acceptable
conversion) 1> could be 'built-in C++
operator==(std::_Bool_type, std::_Bool_type)' 1> c:\program
files (x86)\microsoft visual studio 10.0\vc\include\exception(470): or
'bool std::operator ==(const std::_Exception_ptr &,const
std::_Exception_ptr &)' 1> c:\program files (x86)\microsoft
visual studio 10.0\vc\include\exception(475): or 'bool
std::operator ==(std::_Null_type,const std::_Exception_ptr &)' 1>
c:\program files (x86)\microsoft visual studio
10.0\vc\include\exception(481): or 'bool std::operator ==(const std::_Exception_ptr &,std::_Null_type)' 1> c:\program files
(x86)\microsoft visual studio 10.0\vc\include\system_error(408): or
'bool std::operator ==(const std::error_code &,const
std::error_condition &)' 1> c:\program files (x86)\microsoft
visual studio 10.0\vc\include\system_error(416): or 'bool
std::operator ==(const std::error_condition &,const std::error_code
&)' 1> while trying to match the argument list
'(std::tr1::shared_ptr<_Ty>, const
anonymous-namespace’::)’
1> with 1> [ 1> _Ty=StringClass 1>
] 1> c:\program files (x86)\microsoft visual studio
10.0\vc\include\algorithm(74) : see reference to function template instantiation ‘_InIt
std::_Find*,anonymous-namespace'::<lambda0>>(_InIt,_InIt,const
anonymous-namespace’:: &)’ being compiled 1> with
1> [ 1> _InIt=std::tr1::shared_ptr
*, 1> _Ty=StringClass 1> ] 1> c:\svn\trunk\test\test\test.cpp(55) : see reference to function
template instantiation ‘_InIt
std::find,anonymous-namespace'::<lambda0>>(_InIt,_InIt,const
_Ty &)' being compiled 1> with 1> [ 1> _InIt=std::_Vector_iterator<std::_Vector_val<std::tr1::shared_ptr<StringClass>,std::allocator<std::tr1::shared_ptr<StringClass>>>>, 1>
_Myvec=std::_Vector_val<std::tr1::shared_ptr<StringClass>,std::allocator<std::tr1::shared_ptr<StringClass>>>,
1> _Ty=
anonymous-namespace’:: 1> ] 1>
stdafx.cpp 1> Generating Code… 1> 1>Build FAILED. 1> 1>Time Elapsed
00:00:00.87
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  • 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-18T11:10:12+00:00Added an answer on June 18, 2026 at 11:10 am

    You want to use find_if, not find. Find searches for a value, find_if takes a predicate.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

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.