no matching function for call to 'std::shared_ptr<int>::shared_ptr(int)'
时间: 2023-08-17 18:23:27 浏览: 131
这个错误通常是因为您在使用 `std::shared_ptr` 时,将一个非指针类型的值传递给了构造函数。 `std::shared_ptr` 的构造函数需要接受一个指针类型的参数。
例如,下面的代码会导致这个错误:
```
int i = 10;
std::shared_ptr<int> ptr(i); // 错误:不能将整型变量作为参数传递给 std::shared_ptr 的构造函数
```
正确的做法是将指针地址传递给构造函数,即:
```
int i = 10;
std::shared_ptr<int> ptr(new int(i)); // 正确:传递了指针地址给 std::shared_ptr 的构造函数
```
这样就能够顺利地创建一个 `std::shared_ptr` 类型的智能指针了。
相关问题
error: no matching function for call to ‘std::unique_ptr<StoreService>::unique_ptr(std::string&, int&)’
这个错误信息通常表示在创建 `unique_ptr` 对象时,参数类型与所期望的不符。可能是你在创建 `unique_ptr` 对象时传递了错误的参数类型。
请检查你的代码,确保你传递给 `unique_ptr` 构造函数的参数类型与 `StoreService` 的构造函数所需的参数类型匹配。另外,也要确保你已经在代码中包含了 `string` 类型所需的头文件。
error: no matching function for call to ‘std::map<int, std::__cxx11::basic_string<char> >::count(std::__cxx11::string&)
这个错误是因为你正在尝试使用一个 `std::map` 对象的 `count` 函数来查找一个 `std::__cxx11::string` 键,而 `count` 函数的参数应该与 `std::map` 对象的键类型相匹配。在这种情况下,`std::map` 的键类型为 `int`,而你提供的参数类型为 `std::__cxx11::string`。
要解决这个问题,你需要确保参数类型与 `std::map` 的键类型相匹配。如果你想在 `std::map<int, std::__cxx11::basic_string<char>>` 中查找一个字符串键,你可以使用 `std::map` 的 `find` 函数。例如:
```cpp
std::map<int, std::__cxx11::basic_string<char>> myMap;
std::__cxx11::string key = "example";
auto it = myMap.find(key);
if (it != myMap.end()) {
// 键存在于 map 中
} else {
// 键不存在于 map 中
}
```
这样,你就可以使用 `find` 函数来查找指定的字符串键。