dimanche 9 avril 2023

C2665 none of the 2 overloads could convert all the argument type [duplicate]

I am trying to create a static member to a class that will contain every object of that class. I created another class called Map and it has only a map variable and 2 methods: Insert. But when i tried to use the Insert method on the static var in my constructor it gave me the C2665 Error: None of the 2 overloads could convert all the argument types.

I have read many posts and the Microsoft documentation about this error but I could not find the difference between the definition and the argument list.

This is Map class def:

template <typename _Tv>
class Map
{
public:
    std::map<std::string, _Tv> myMap;
    std::pair<typename std::map<std::string, _Tv>::iterator, bool> Insert(_Tv&);
    std::pair<typename std::map<std::string, _Tv>::iterator, bool> Insert(std::pair<std::string&, _Tv>&); 
}

This is the static member:

public:
    static Map<VideoSource*> videoSources;

The definition in the same file:

extern Map<VideoSource*> videoSources;

And in the source file:

Map<VideoSource*> VideoSource::videoSources;

VideoSource::VideoSource(std::string path, std::string name) : ISource(path), IImg(), IPlayable()
{
    VideoSource::videoSources.Insert(std::make_pair(name, this)); // returns error from the compiler
}

This is the error message:

1>D:\C++\VideoEditor\VideoEditor\Map.h(11,65): message : could be 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,_Tv>>>>,bool> Map<_Tv>::Insert(std::pair<std::string &,_Tv> &)'
1>        with
1>        [
1>            _Tv=VideoSource *
1>        ]
1>D:\C++\VideoEditor\VideoEditor\Map.h(10,65): message : or       'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,_Tv>>>>,bool> Map<_Tv>::Insert(_Tv &)'
1>        with
1>        [
1>            _Tv=VideoSource *
1>        ]
1>D:\C++\VideoEditor\VideoEditor\VideoSource.cpp(12,27): message : 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,_Tv>>>>,bool> Map<_Tv>::Insert(_Tv &)': cannot convert argument 1 from 'std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,VideoSource>' to '_Tv &'
1>        with
1>        [
1>            _Tv=VideoSource *
1>        ]
1>D:\C++\VideoEditor\VideoEditor\Map.h(10,65): message : see declaration of 'Map<VideoSource *>::Insert'
1>D:\C++\VideoEditor\VideoEditor\VideoSource.cpp(12,64): message : while trying to match the argument list '(std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,VideoSource>)'

Can someone please help me? I have no idea what i did wrong

Aucun commentaire:

Enregistrer un commentaire