:C++ şablon derleme hatası: beklenen birincil-ifade önce '>' belirteci
#include <iostream>
#include <boost/property_tree/ptree.hpp>
void foo(boost::property_tree::ptree &pt)
{
std::cout << pt.get<std::string>("path"); // <---
}
int main()
{
boost::property_tree::ptree pt;
foo(pt);
return 0;
}
Ama en kısa sürede şablonları ekleyin olarak ve
test_ptree.cpp: In function ‘void foo(ptree&)’:
test_ptree.cpp:7: error: expected primary-expression before ‘>’ token
: Ben bir hata GCC olsun
template<class ptree>
void foo(ptree &pt)
içine foo
prototipi değiştirmek MSVC++ ileama hata yok! Hata, <---
işaretli satırındadır. Ben
--- std::cout << pt.get<std::string>("path"); // <---
+++ std::cout << pt.get("path", "default value");
içine sorun hattını değiştirirseniz Ve yine, hata (sorun açık <std::string>
içindedir) kaybolur. Boole> = 1,41 gerektirir.
Boost.PropertyTree gerektirir. Lütfen bu hatayı anlamak ve düzeltmek için bana yardımcı olun. diğer iyi cevapları ve açıklamaları içeren benzer bir popüler soru -
Templates: template function not playing well with class’s template member function bakınız.
std::cout << pt.template get<std::string>("path");
kullanın template
aynı durumda typename
olarak, şablon üyelerinin yerine türleri hariç:
İlgili: http://stackoverflow.com/questions/1682844/ templates-template-function-not-with-sınıflar-şablon-üye-functi/1682885 (Duplicate?) – GManNickG
Evet, bu bir çoğalt. Yardımın için teşekkürler! –