Hallo,
ich versuche schon seit Stunden folgendes Problem zu lösen. Hier erstmal
das Minimalbeispiel in C++:
1 | #include <iostream>
|
2 | #include <string>
|
3 | #include <thread>
|
4 |
|
5 | template <typename T>
|
6 | class Queue
|
7 | {
|
8 | public:
|
9 | T pop() {}
|
10 | void push(const T& item) {}
|
11 | };
|
12 |
|
13 | void produce(Queue<int>& q) {
|
14 | q.push(1234);
|
15 | }
|
16 |
|
17 | // wenn diese Funktion auskommentiert ist, funktioniert es
|
18 | void produce(Queue<std::string>& q) {
|
19 | q.push("Hallo");
|
20 | }
|
21 |
|
22 | int main()
|
23 | {
|
24 | Queue<int> my_queue;
|
25 | auto f = std::bind(&produce, my_queue); // <<< FEHLER
|
26 | }
|
Übersetzt habe ich das mit:
1 | g++ -Wall -Wextra -pedantic-errors -std=c++0x -O2 -pthread producer_consumer1.cpp -o producer_consumer1
|
Ich habe eine Template-Klasse Queue geschrieben. Ich erzeuge eine Queue,
welche erstmal nur ints aufnehmen soll. Eine überladene Funktion produce
bekommt diese Queue und füllt diese mit einem Int-Wert. Soweit
funktioniert das erstmal.
Habe ich allerdings eine zweite Funktion produce (Zeile 18), welche eine
String-Queue übergeben bekommt, erhalte ich die Fehlermeldung:
1 | producer_consumer1.cpp: In function ‘int main()’:
|
2 | producer_consumer1.cpp:25:40: error: no matching function for call to ‘bind(<unresolved overloaded function type>, Queue<int>&)’
|
3 | auto f = std::bind(&produce, my_queue); // <<< FEHLER
|
Kann mir jemand weiterhelfen?