Głównie chodzi o dedukcje typu, abym mógł wypełniać klasą Filler
prywatne pole klasy Foo
Wg wszelkich źródeł czytanych kod powinien się kompilować, a nie kompiluje (na ideone jest OK).
Już dwa razy przeinstalowałem VS i nadal nic (od wczoraj łapie zwiechy).
Zerknijcie, jak możecie czy to jest OK (czy to nie jakiś bug - szukam dalej).
#include <iostream>
#include <string>
#include <map>
#include <type_traits>
using namespace std;
using MapSS = map<string, string>;
class Printer {
public:
template <class C>
void print(const C& coll) {
for (auto const& el : coll)
cout << el.first << " " << el.second << '\n';
cout << '\n';
}
};
class Filler {
public:
template <class C>
void fill(C& coll) {
string key, value;
cin >> key >> value;
using deducedType = typename decay_t<C>::value_type;
deducedType deducedValue = { key, value };
coll.insert(std::forward<deducedType>(deducedValue));
}
};
class Foo{
MapSS coll;
public:
Foo() = default;
void appendToMap() {
for (int i = 0; i < 3; ++i) {
Filler filler;
filler.fill(coll);
}
}
void showMap() const {
Printer printer;
printer.print(coll);
}
};
int main()
{
Foo f;
f.appendToMap();
f.showMap();
}
Error C2065 'deducedValue': undeclared identifier
Error C2146 syntax error: missing ';' before identifier 'deducedValue'