Error with xstdde "could not deduce template argument..." - c++

I'm working on a asteroids game replica. This error I'm getting is beyond my understanding so I hope you can help.
In my code I have a class name asteroid that stores every asteroid object. Within this class I have a public function that's called create() which has the parameter sf::ConvexShape (if you don't know what sf::ConvexShape is, it is a function in the SFML library). I also have a std::map<asteroid, sf::ConvexShape> to store asteroid objects as the key and their shapes as the .second
The error is a runtime error, everything is fine in the compiler. The error reports are gibberish to me, but there was a part that mentioned "iterator" and "std::vector" which makes me think I'm doing something wrong passing iterators to the create() function?
Here is the error log:
Error 5 error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing
Error 10 error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing
Error 12 error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing
Error 9 error C2784: 'bool std::operator <(const std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::move_iterator<_RanIt> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing
Error 8 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing
Error 6 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing
Error 4 error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing
Error 11 error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing
Error 7 error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing
Error 13 error C2676: binary '<' : 'const asteroid' does not define this operator or a conversion to a type acceptable to the predefined operator C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing
Also full sauce here.
Why am I getting these errors? How can I fix it?
Let me know if there is something I forgot to mention, its hard to know what to ask when I don't understand the problem.

std::map stores things in a sorted order. If you don't tell it how to sort, it will use operator <. Your problem is that given:
asteroid a, b;
a < b; // Not defined.
You need something like:
bool operator <( const asteroid& lhs, const asteroid& rhs)
{
????
}
Except that you can't use the position (because that keeps changing). Perhaps you should do:
class asteroid
{
static unsigned global_id;
unsigned id;
.... // Previous contents as before.
}
asteroid::asteroid() : id (global_id++) { ... }
and then
bool operator <( const asteroid& lhs, const asteroid& rhs)
{
lhs.id < rhs.id;
}

Related

What does the istream extraction operator >> return?

I'm trying to get Solipsis to compile in Visual Studio 2017(it was written for VS 2005)
I can't figure out what this code is trying to do:
template<typename T>
bool from_string( const char* Str, T & Dest )
{
// créer un flux à partir de la chaîne donnée
std::istringstream iss( Str );
// tenter la conversion vers Dest
return iss >> Dest != 0;
}
It gets the following error
1>c:\users\root\source\repos\solipsis3d\sources\modelers\mdlrtools\include\SolipsisErrorHandler.h(91): error C2678: binary '!=': no operator found which takes a left-hand operand of type 'std::basic_istream<char,std::char_traits<char>>' (or there is no acceptable conversion)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\exception(347): note: could be 'bool std::operator !=(const std::exception_ptr &,const std::exception_ptr &) throw()' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\exception(352): note: or 'bool std::operator !=(std::nullptr_t,const std::exception_ptr &) throw()' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\exception(357): note: or 'bool std::operator !=(const std::exception_ptr &,std::nullptr_t) throw()' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\system_error(379): note: or 'bool std::operator !=(const std::error_code &,const std::error_code &) noexcept' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\system_error(384): note: or 'bool std::operator !=(const std::error_code &,const std::error_condition &) noexcept' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\system_error(389): note: or 'bool std::operator !=(const std::error_condition &,const std::error_code &) noexcept' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\system_error(394): note: or 'bool std::operator !=(const std::error_condition &,const std::error_condition &) noexcept' [found using argument-dependent lookup]
1>c:\users\root\source\repos\solipsis3d\sources\modelers\mdlrtools\include\SolipsisErrorHandler.h(91): note: or 'built-in C++ operator!=(bool, int)'
1>c:\users\root\source\repos\solipsis3d\sources\modelers\mdlrtools\include\SolipsisErrorHandler.h(91): note: while trying to match the argument list '(std::basic_istream<char,std::char_traits<char>>, int)'
1>src\Object3D.cpp(220): note: see reference to function template instantiation 'bool Solipsis::from_string<bool>(const char *,T &)' being compiled
1> with
1> [
1> T=bool
1> ]
1>c:\users\root\source\repos\solipsis3d\sources\modelers\mdlrtools\include\SolipsisErrorHandler.h(91): error C2446: '!=': no conversion from 'int' to 'std::basic_istream<char,std::char_traits<char>>'
1>c:\users\root\source\repos\solipsis3d\sources\modelers\mdlrtools\include\SolipsisErrorHandler.h(91): note: Constructor for class 'std::basic_istream<char,std::char_traits<char>>' is declared 'explicit'
1>SolipsisErrorHandler.cpp
In human language what is the return value of the '>>' operator(when used as for extraction not bit shift)? What has changed about it since VS 2005 that makes the code snippet not work?
I can't figure out what this code is trying to do:
The code is trying to return whether the stream extraction was successful or not.
What does the istream extraction operator >> return?
It is not the case that the return type of the operator is breaking your compilation, but rather because of a change in behaviour since C++11.
Prior to C++11 (say with VS2005) you could check for success/failure by comparing the istream object with true/false.
return iss >> Dest != 0;
You can't do that with a C++11 compilation (say with VS2017), and the reasons are given in the excellent answer to the suggested duplicate question:
Evaluating stream operator >> as boolean
Rather modernise your function by casting to a boolean.
return bool(iss >> Dest);

SFML and STL: What's wrong with my code?

I have the following code snippets:
void RemoveButton::triggerAction(team &team, unsigned int index)
{
switch (mAction)
{
case Action::remove:
{
//team.mTeamMembers.erase(std::remove(team.mTeamMembers.begin(), team.mTeamMembers.end(), team.mTeamMembers.at(index)), team.mTeamMembers.end());
team.mTeamMembers.erase(team.mTeamMembers.begin() + index);
for (unsigned int i = index; i < team.mTeamMembers.size(); i++)
{
team.mTeamMembers[i].mRemoveButton->getText().move(0.0f, -30.0f);
team.mTeamMembers[i].mText.move(0.0f, -30.0f);
}
team.mAddPosition.y -= 30.0f;
break;
}
default:break;
}
}
class team
{
public:
size_t teamNumber;
std::vector<AddButton> mAddButtons;
std::vector<teamRecord> mTeamMembers;
sf::Sprite mBorder;
sf::Text mText;
Selector<AddButton> mAddButtons_Selector;
sf::Vector2f mAddPosition;
Selector<teamRecord> mTeamMembers_Selector;
team(sf::Vector2f borderPosition, sf::Vector2f removeButtonsPosition, sf::Vector2f textPosition, size_t teamNumb, std::string text);
};
How should I erase an element from the team.mTeamMembers STL vector? The way I do it currently results in seemingly random execution errors, specifically when clicking the non-existent sprite of a deleted button. The commented line that uses std::remove is not compiled, and I do not understand why. As I'm feeling confused a.f. , can someone please shine some light here? Here's the build log while using std::remove, as recommended by some users on this forum:
1>------ Build started: Project: Complex OOP Menus, Configuration: Release Win32 ------
1> RemoveButton.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\algorithm(1454): error C2678: binary '==': no operator found which takes a left-hand operand of type 'teamRecord' (or there is no acceptable conversion)
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(389): note: could be 'bool std::operator ==(const std::error_condition &,const std::error_condition &) noexcept'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(381): note: or 'bool std::operator ==(const std::error_condition &,const std::error_code &) noexcept'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(373): note: or 'bool std::operator ==(const std::error_code &,const std::error_condition &) noexcept'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(365): note: or 'bool std::operator ==(const std::error_code &,const std::error_code &) noexcept'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\exception(339): note: or 'bool std::operator ==(const std::exception_ptr &,std::nullptr_t) throw()'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\exception(334): note: or 'bool std::operator ==(std::nullptr_t,const std::exception_ptr &) throw()'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\exception(329): note: or 'bool std::operator ==(const std::exception_ptr &,const std::exception_ptr &) throw()'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\algorithm(1454): note: while trying to match the argument list '(teamRecord, const teamRecord)'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\algorithm(1467): note: see reference to function template instantiation '_FwdIt std::_Remove_unchecked<teamRecord*,_Ty>(_FwdIt,_FwdIt,const _Ty &)' being compiled
1> with
1> [
1> _FwdIt=teamRecord *,
1> _Ty=teamRecord
1> ]
1> ..\Data\Source\RemoveButton.cpp(24): note: see reference to function template instantiation '_FwdIt std::remove<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<teamRecord>>>,teamRecord>(_FwdIt,_FwdIt,const _Ty &)' being compiled
1> with
1> [
1> _FwdIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<teamRecord>>>,
1> _Ty=teamRecord
1> ]
If there is not enough information here, I could post the github link to my project, but it's pretty big and it would take time to sift through the code.
Using std::remove() doesn't make any sense to me if you already know the position/offset and you only want to remove a single entry.
You're receiving your error with std::remove() most likely due to the fact that there's no equality operator (operator ==) defined for your teamRecord class (or it just isn't found).
The way I do it currently results in seemingly random execution errors, specifically when clicking the non-existent sprite of a deleted button.
That's something we can't look at unless we see the code regarding that. How can you click something not existing? Any chance you're just missing a check or not cleaning up things properly?
I solved this by double checking the index I was giving to the elements on insertion. Thanks and sorry for such a stupid mistake!

Priority queue works with vectors but not lists

I am tightening up some rendering code and instead of storing all my renderable objects in a plain ol vector I decided to use a priority queue (this way things like transparency can be automatically prioritized correctly). I cannot get it to work with a list as the underlying data structure however. I have tried it using both a functor and by overloading the < operator. It complains about:
Error 8 error C2676: binary '-' : 'std::_List_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' does not define this operator or a conversion to a type acceptable to the predefined operator c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2425 1 ObjLoaded
Error 4 error C2676: binary '-' : 'std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' does not define this operator or a conversion to a type acceptable to the predefined operator c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2331 1 ObjLoaded
Error 7 error C2784: 'unknown-type std::operator -(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::_List_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2425 1 ObjLoaded
Error 3 error C2784: 'unknown-type std::operator -(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2331 1 ObjLoaded
Error 6 error C2784: 'unknown-type std::operator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::_List_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2425 1 ObjLoaded
Error 2 error C2784: 'unknown-type std::operator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2331 1 ObjLoaded
Error 5 error C2784: 'unknown-type std::operator -(std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'std::move_iterator<_RanIt> &' from 'std::_List_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2425 1 ObjLoaded
Error 1 error C2784: 'unknown-type std::operator -(std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'std::move_iterator<_RanIt> &' from 'std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<IRenderable *>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 2331 1 ObjLoaded
This is how I am declaring the priority queue:
priority_queue<IRenderable*, list<IRenderable*>> m_renderlist;
with the overloaded < operator. If I make one simple change, everything runs:
priority_queue<IRenderable*, vector<IRenderable*>> m_renderlist;
Any Idea why might be happening here? For completeness, here is my overload and functor:
bool IRenderable::operator<(const IRenderable* comp)
{
if (this->GetPriority() < comp->GetPriority())
return true;
return false;
}
//class IRenderableComp
//{
//public:
// bool operator()(const IRenderable* first, const IRenderable* second)
// {
// if (first->GetPriority() < second->GetPriority())
// return true;
// return false;
// }
//};
Not super important because I can get it working with vectors, but this little stuff bugs me and I want to understand why. Any insight would be appreciated. Thanks
23.6.4/1 Any sequence container with random access iterator and supporting operations front(), push_back() and pop_back() can be used to instantiate priority_queue.
23.3.5.1/1 list is a sequence container that supports bidirectional iterators...
Emphasis mine.

error C2784 ,class in key map

I have a problem with the container map. I need to store my own class Person in key but i have error C2784 (i.e., "The compiler cannot determine a template argument from the supplied function arguments."). It's example from the book "Ivor Horton's beginning Visual C++ 2010"
#include<map>
#include<string>
#include <iostream>
using namespace std;
void main()
{
class Person{
public:
string c_name,c_surname;
Person(string name,string surname){
c_name=name;
c_surname=surname;
}
};
map<Person,string> phonebook;
phonebook.insert(make_pair(Person("Mel","GIBSON"),"24 32 23"));
phonebook[Person("Mel2","Gibson2")]="243 32 23";
/* it doesn`t work too
typedef pair<Person,string> Entry;
Entry entry1= Entry(Person("Jack","Jones"),"213 567 1234");
phonebook.insert(entry1);*/
system("Pause");
}
Error 1 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const main::Person' e:\microsoft visual studio 10.0\vc\include\xfunctional 125 1 AllClasses
Error 2 error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'const main::Person' e:\microsoft visual studio 10.0\vc\include\xfunctional 125 1 AllClasses
Error 3 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const main::Person' e:\microsoft visual studio 10.0\vc\include\xfunctional 125 1 AllClasses
Error 4 error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const main::Person' e:\microsoft visual studio 10.0\vc\include\xfunctional 125 1 AllClasses
Error 5 error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const main::Person' e:\microsoft visual studio 10.0\vc\include\xfunctional 125 1 AllClasses
Error 6 error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const main::Person' e:\microsoft visual studio 10.0\vc\include\xfunctional 125 1 AllClasses
Error 7 error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const main::Person' e:\microsoft visual studio 10.0\vc\include\xfunctional 125 1 AllClasses
Error 8 error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const main::Person' e:\microsoft visual studio 10.0\vc\include\xfunctional 125 1 AllClasses
Error 9 error C2676: binary '<' : 'const main::Person' does not define this operator or a conversion to a type acceptable to the predefined operator e:\microsoft visual studio 10.0\vc\include\xfunctional 125 1 AllClasses
The problem here is that std::map requires your keys to be comparable with the < operator. Custom structures/classes are not that by default, you need to make a custom operator< for comparison.
In C++03 you could not use local classes (classes defined within functions) as template arguments.
In C++11 you can.
So one fix is to update the compiler (there is Visual C++ 2013), and another fix is to move the class definition out of main.
By the way, void main is invalid as standard C++, and as standard C, and it's more to type than standard int main. If your book has void main, then that's a very ungood book. Microsoft's examples that include void main are also very ungood.
Also, by the way, the
system("Pause");
at the end is also very ungood practice because
it is not necessary, has no advantage, but
it makes the program more difficult to use and has some other problems, and to top it all,
it's Windows-specific, non-portable code.
To run a console program so that it stops at the end
in Visual Studio use Ctrl+F5, or
in Visual Studio place a breakpoint at the end of main (just click in the left margin) and run it with debugging (e.g. via keypress F5), or
run it from a command interpreter.
UPDATE: the now added error messages (even the first one) mention operator<. You need to define that also. That is, define an operator< function for your class Person.

Creating boost::thread with an std::shared_ptr object instance

I have the following two code segments. The first block compiles and works as expected. However the second block does not compile.
My question is, given the code below what is the correct syntax when trying to create a thread based on an instance of an object that is being proxied by a shared_ptr?
#include <iostream>
#include <new>
#include <memory>
#include <boost/thread.hpp>
struct foo
{
void boo() {}
};
int main()
{
//This works
{
foo* fptr = new foo;
boost::thread t(&foo::boo,fptr);
t.join();
delete fptr;
}
//This doesn't work
{
std::shared_ptr<foo> fptr(new foo);
boost::thread t(&foo::boo,fptr);
t.join();
}
return 0;
}
The compiler error:
Error 5 error C2784: 'T *boost::get_pointer(T *)' : could not deduce template argument for 'T *' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 3 error C2784: 'T *boost::get_pointer(const std::auto_ptr<_Ty> &)' : could not deduce template argument for 'const std::auto_ptr<_Ty> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 4 error C2784: 'T *boost::get_pointer(const std::auto_ptr<_Ty> &)' : could not deduce template argument for 'const std::auto_ptr<_Ty> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 8 error C2784: 'T *boost::get_pointer(const boost::shared_ptr<X> &)' : could not deduce template argument for 'const boost::shared_ptr<X> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 9 error C2784: 'T *boost::get_pointer(const boost::shared_ptr<X> &)' : could not deduce template argument for 'const boost::shared_ptr<X> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 1 error C2784: 'T *boost::get_pointer(const boost::scoped_ptr<T> &)' : could not deduce template argument for 'const boost::scoped_ptr<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 2 error C2784: 'T *boost::get_pointer(const boost::scoped_ptr<T> &)' : could not deduce template argument for 'const boost::scoped_ptr<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 6 error C2784: 'T *boost::get_pointer(const boost::reference_wrapper<T> &)' : could not deduce template argument for 'const boost::reference_wrapper<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 7 error C2784: 'T *boost::get_pointer(const boost::reference_wrapper<T> &)' : could not deduce template argument for 'const boost::reference_wrapper<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 10 error C2784: 'T *boost::get_pointer(const boost::intrusive_ptr<T> &)' : could not deduce template argument for 'const boost::intrusive_ptr<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 11 error C2784: 'T *boost::get_pointer(const boost::intrusive_ptr<T> &)' : could not deduce template argument for 'const boost::intrusive_ptr<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
The problem is that boost::thread relies on boost::mem_fn to handle member functions, and boost::mem_fn (or at least the version you are using) doesn't know how to use a std::shared_ptr to invoke a member function as it expects you to use boost::shared_ptr or one of the myriad of other smart pointer types in your error listing.
The raw pointer works because boost::mem_fn already has that overload. The solutions are to use boost::shared_ptr or std::mem_fn. The latter works because std::mem_fn knows how to interact with std::shared_ptr
boost::thread t(std::mem_fn(&foo::boo), fptr);
An alternative to Dave S's answer is to define this (before <boost/mem_fn.hpp> gets included):
namespace boost
{
template<typename T>
inline T*
get_pointer(const std::shared_ptr<T>& p)
{ return p.get(); }
}
That "teaches" boost::mem_fn to obtain a raw pointer from a std::shared_ptr.
In C++11 std::mem_fn is required to work with any pointer-like type, simply by dereferencing it i.e. *fptr, but boost::mem_fn instead uses *boost::get_pointer(fptr). I don't know if it's fixed in the latest version of Boost, but I would argue that it should use SFINAE to detect whether get_pointer will work, and should just dereference it otherwise.