This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
std::to_string - more than instance of overloaded function matches the argument list
#include <string>
int main()
{
double randDouble = 1245.432;
std::wstring stringDouble = std::to_wstring(randDouble);
}
When I compile this in Visual Studio 2010 I get this error
Error 1 error C2668: 'std::to_wstring' : ambiguous call to overloaded
function 6
1> error C2668:
'std::to_string' : ambiguous call to overloaded function
1> d:\program files (x86)\microsoft visual studio
10.0\vc\include\string(688): could be 'std::string std::to_string(long double)'
1> d:\program files (x86)\microsoft visual studio
10.0\vc\include\string(680): or 'std::string std::to_string(_ULonglong)'
1> d:\program files
(x86)\microsoft visual studio 10.0\vc\include\string(672): or
'std::string std::to_string(_Longlong)'
Can someone please explain to me why the compiler is confused and what am I doing wrong?
This was a bug in Visual C++ 2010. It has been fixed in Visual C++ 2012.
Related
After downloading this https://github.com/pybind/pybind11/archive/v2.2.3.zip
and creating a simple cpp file:
#include <pybind11/pybind11.h>
int add(int i, int j) { return i + j; }
PYBIND11_MODULE(example, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add", &add, "A function which adds two numbers");
}
with
I get this error
Error C2446 '<': no conversion from 'unsigned __int64' to 'unsigned __int64 *' in c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector line 2326
Would anybody know what this could be referring to, and possibly how to fix it?
As requested, here the full error log:
1>------ Rebuild All started: Project: Test_CreatePythonBindings, Configuration: Debug x64 ------
1>example.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): error C2446: '<': no conversion from 'unsigned __int64' to 'unsigned __int64 *'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): note: Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2325): note: while compiling class template member function 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>> &std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>::operator +=(__int64)'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2545): note: see reference to function template instantiation 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>> &std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>::operator +=(__int64)' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2490): note: see reference to class template instantiation 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(3094): note: see reference to class template instantiation 'std::_Vb_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(3093): note: while compiling class template member function 'void std::vector<bool,std::allocator<_Ty>>::push_back(const bool &)'
1> with
1> [
1> _Ty=bool
1> ]
1>c:\pybind11-2.2.3\include\pybind11\pybind11.h(513): note: see reference to function template instantiation 'void std::vector<bool,std::allocator<_Ty>>::push_back(const bool &)' being compiled
1> with
1> [
1> _Ty=bool
1> ]
1>c:\pybind11-2.2.3\include\pybind11\cast.h(1806): note: see reference to class template instantiation 'std::vector<bool,std::allocator<_Ty>>' being compiled
1> with
1> [
1> _Ty=bool
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): warning C4554: '&': check operator precedence for possible error; use parentheses to clarify precedence
1>Done building project "Test_CreatePythonBindings.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
It appears to be a VS 2017 issue related to
std::vector<bool>
Separate question asked here:
Pushback on vector<bool> fails - VS 2017
I get a following compiler (vs2012) error:
Error 3 error C2679: binary '+=' : no operator found which takes a
right-hand operand of type 'const std::chrono::duration<_Rep,_Period>'
(or there is no acceptable conversion) c:\program files
(x86)\microsoft visual studio 11.0\vc\include\chrono 749
My definition of duration is:
// Tick interval type in nanoseconds
typedef std::chrono::duration<double, std::ratio<1, 100000000>> tick_interval_type;
Same error when I use float... It only compiles when the Rep type of duration is integer.
Can someone please help?
Edit (more complete log from Output):
c:\program files (x86)\microsoft visual studio
11.0\vc\include\chrono(749): error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const
std::chrono::duration<_Rep,_Period>' (or there is no acceptable
conversion) with [
_Rep=double,
_Period=std::nano ] c:\program files (x86)\microsoft visual studio 11.0\vc\include\chrono(166): could be 'std::chrono::duration<_Rep,_Period>
&std::chrono::duration<_Rep,_Period>::operator +=(const
std::chrono::duration<_Rep,_Period> &)' with [
_Rep=__int64,
_Period=std::nano ] while trying to match the argument list '(std::chrono::nanoseconds, const
std::chrono::duration<_Rep,_Period>)' with [
_Rep=double,
_Period=std::nano ] c:\program files (x86)\microsoft visual studio 11.0\vc\include\thread(164) : see reference to function template instantiation 'xtime std::_To_xtime(const
std::chrono::duration<_Rep,_Period> &)' being compiled with [
_Rep=double,
_Period=std::nano ] c:\dev\projects\revolverx\classes\ticker.h(78) : see reference to function template instantiation 'void
std::this_thread::sleep_for(const
std::chrono::duration<_Rep,_Period> &)' being compiled with [
_Rep=double,
_Period=std::nano ]
<chrono> in Visual Studio is broken. It doesn't work with mixed type arithmetic, which, arguably, is one of the main features of <chrono>. You get this error because one of the sides uses __int64 nanos and the other uses double nanos.
I recommend either dropping it in favor of a real C++ implementation, or using Boost.Chrono.
Update: I've come upon this question four years after it was originally posted, and I've tested this on Visual Studio 2015. It does compile now. For example:
#include <iostream>
#include <iomanip>
#include <chrono>
int main()
{
typedef std::chrono::duration<double, std::ratio<1, 100000000>> tick_interval_type; // Originally posted line
tick_interval_type tick {0};
tick += std::chrono::microseconds(3);
std::cout << std::setprecision(6) << std::fixed << tick.count();
return 0;
}
Output:
300.000000
Looking at A previous stack Question of std:make_shared vs std::shared_ptr, I have tried to implement this in a uni project. This was the previous 'question':
I can't think of any situation where
std::shared_ptr<Object> obj(new Object("foo", 1));
would be preferred to
auto obj = std::make_shared<Object>("foo", 1);
Thus I have taken this code:
std::shared_ptr<Triangle> pT1(new Triangle(pCanvas, 30, 30, 30, 60, 60, 30, 255, 0, 0));
And modified it to this code:
auto pT1 = std::make_shared<Triangle>(pCanvas, 30, 30, 30, 60, 60, 30, 255, 0, 0);
However, std::make_shared is underlined in red, and when I mouse-over it i get the error:
"Error: no instance of overloaded function "std::make_shared" matches the argument list"
My code compiles and executes correctly with the first line of code, but if I use the second, there are some errors.
These errors are:
`1>------ Build started: Project: SIT153Canvas, Configuration: Debug Win32 ------
1> main.cpp
1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(_V0_t &&,_V1_t &&,_V2_t &&,_V3_t &&,_V4_t &&)' : expects 5 arguments - 10 provided
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'
1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(_V0_t &&,_V1_t &&,_V2_t &&,_V3_t &&)' : expects 4 arguments - 10 provided
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'
1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(_V0_t &&,_V1_t &&,_V2_t &&)' : expects 3 arguments - 10 provided
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'
1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(_V0_t &&,_V1_t &&)' : expects 2 arguments - 10 provided
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'
1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(_V0_t &&)' : expects 1 arguments - 10 provided
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'
1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(void)' : expects 0 arguments - 10 provided
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'
According to the error, std::make_shared seems to only expect a maximum of 5 arguments.
Other websites I've searched unfortunately don't shed any light on the problem.
Any help would be appreciated.
VS2012 doesn't fully support variadic templates. There is no compiler support - instead, they are simulated in the library, up to 5 parameters by default. The actual number is determined by the macro _VARIADIC_MAX. Define it in your project properties to a sufficiently large value.
This works in Visual Studio 2010, but it does not in 2012 Update 2 (with Boost 1.5.3):
vector<vector<BYTE>> data = assign::list_of (assign::list_of (0x06)(0x02));
The error given by the compiler (updated):
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory0(617): error C2668: 'std::vector<_Ty>::vector' : ambiguous call to overloaded function
with
[
_Ty=BYTE
]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\vector(786): could be 'std::vector<_Ty>::vector(std::vector<_Ty> &&)'
with
[
_Ty=BYTE
]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\vector(693): or 'std::vector<_Ty>::vector(unsigned __int64)'
with
[
_Ty=BYTE
]
while trying to match the argument list '(boost::assign_detail::generic_list<T>)'
with
[
T=int
]
... (dozens of more lines)
Any way to work around this error?
I do not think the problem is from embedding, it is from creating a temporary value using list_of. That should work:
vector<BYTE> temp = assign::list_of (0x06)(0x02);
vector<vector<Byte> > data = assign::list_of(temp);
I don't have VC11 so just a wild guess... Probably VC11 is confused because your integers can be converted to BYTE and so move-constructor would be used or to size_t and so std::vector(size_t) constructor would be used.
Please try to convert to BYTE yourself to avoid implicit conversion:
vector<vector<BYTE>> data = assign::list_of (assign::list_of (static_cast<BYTE>(0x06))(static_cast<BYTE>(0x02)));
You need to help boost::assign::list_of a little with the template parameters:
// C2668:
std::vector<std::vector<int>> foo1 =
boost::assign::list_of(boost::assign::list_of(0)(1));
// no C2668:
std::vector<std::vector<int>> foo2 =
boost::assign::list_of<std::vector<int>>(boost::assign::list_of(0)(1));
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 12 years ago.
i have following code
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <hash_map>
#include <string>
#include <iterator>
#include <ostream>
using namespace std;
struct Equal
{
bool operator()(const char *s1,const char *s2)const
{
return std::strcmp(s1,s2)==0;
}
};
typedef std::hash_multimap<const char*,int,hash<const char*>,Equal>map_type;
void lookup(const map_type&Map,const char *str){
cout<<str<<":";
pair<map_type::const_iterator ,map_type::const_iterator>p=Map.equal_range(str);
for (map_type::const_iterator i=p.first;i!=p.second;++i)
cout << (*i).second<<" ";
}
int maain(){
map_type m;
m.insert(map_type::value_type("H", 1));
m.insert(map_type::value_type("H", 2));
m.insert(map_type::value_type("C", 12));
m.insert(map_type::value_type("C", 13));
m.insert(map_type::value_type("O", 16));
m.insert(map_type::value_type("O", 17));
m.insert(map_type::value_type("O", 18));
m.insert(map_type::value_type("I", 127));
lookup(M,"I");
lookup(M,"0");
lookup(M,"Rn");
return 0;
}
but here is errors
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2903: 'rebind' : symbol is neither a class template nor a function template
1> c:\program files\microsoft visual studio 10.0\vc\include\xhash(170) : see reference to class template instantiation 'std::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>' being compiled
1> with
1> [
1> _Kty=const char *,
1> _Ty=int,
1> _Tr=std::hash<const char *>,
1> _Alloc=Equal,
1> _Mfl=true
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\hash_map(273) : see reference to class template instantiation 'std::_Hash<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Hmap_traits<const char *,int,std::hash<const char *>,Equal,true>
1> ]
1> c:\users\7\documents\visual studio 2010\projects\hash_tables\hash_tables\hash_tables.cpp(22) : see reference to class template instantiation 'stdext::hash_multimap<_Kty,_Ty,_Tr,_Alloc>' being compiled
1> with
1> [
1> _Kty=const char *,
1> _Ty=int,
1> _Tr=std::hash<const char *>,
1> _Alloc=Equal
1> ]
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2039: 'rebind' : is not a member of 'Equal'
1> c:\users\7\documents\visual studio 2010\projects\hash_tables\hash_tables\hash_tables.cpp(11) : see declaration of 'Equal'
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2143: syntax error : missing ';' before '<'
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2039: 'other' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(27): error C2238: unexpected token(s) preceding ';'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(180): error C2039: 'bucket_size' : is not a member of 'std::hash<_Kty>'
1> with
1> [
1> _Kty=const char *
1> ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(180): error C2065: 'bucket_size' : undeclared identifier
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(184): error C2039: 'allocator_type' : is not a member of 'std::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>'
1> with
1> [
1> _Kty=const char *,
1> _Ty=int,
1> _Tr=std::hash<const char *>,
1> _Alloc=Equal,
1> _Mfl=true
1> ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(184): error C2146: syntax error : missing ',' before identifier 'allocator_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(184): error C2065: 'allocator_type' : undeclared identifier
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(186): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(187): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(188): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(189): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(190): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(191): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(192): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(193): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(197): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2146: syntax error : missing ';' before identifier 'iterator'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C3254: 'std::_Hash<_Traits>' : class contains explicit override 'type' but does not derive from an interface that contains the function declaration
1> with
1> [
1> _Traits=std::_Hmap_traits<const char *,int,std::hash<const char *>,Equal,true>
1> ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2838: 'type' : illegal qualified name in member declaration
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2208: 'std::iterator' : no members defined using this type
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.96
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
please help
You have to look at each complier error and fix them one at a time. We can't take a file of code and fix each error. Learning to live and even on occasion love the abusive spouse that is your complier is part of the process.
All your errors seem related to the fact that you're not passing the right template arguments to hash_multimap. Take a look at hash_multimap's documentation. The last parameter, Ăˆqual` should be the allocator, not a function object, check out the 1st error:
c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2903: 'rebind' : symbol is neither a class template nor a function template
c:\program files\microsoft visual studio 10.0\vc\include\xhash(170) : see reference to class template instantiation 'std::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>' being compiled
with
[
_Kty=const char *,
_Ty=int,
_Tr=std::hash,
_Alloc=Equal,
_Mfl=true
]
Edit:
If you've looked at SGI's hash_multimap documentation, you'll notice that the hash_map and hash_multimap classes are different between vendors because they are not standard. The next version of the standard comprises standard hashed containers. In the mean time, well, you'll have to write non portable code!