Böyle iki typedefs yaşıyorum: Ben düşünün problemindeSTL yineleyiciler std :: mesafe() hatası
typedef std::vector<int> Container;
typedef std::vector<int>::const_iterator Iter;
, ben Container Input
bazı işlemleri gerçekleştirmek ve bundan sonra ben std::distance(Input.begin(),itTarget)
hesaplamak istiyorum Burada itTarget
, Iter
türündendir. Ama ben bu derleyici no instance of function template "std::distance" matches the argument list
ve sadece döküm sonra, yani, std::distance(static_cast<Iter>(Input.begin()),itTarget)
her şey iyi çalışıyor.
Neden böyle olduğunu merak ediyorum?
Çünkü 'begin()' bir const_iterator' döndürmüyor mu? –
Ama bir şekilde olmalı? http://www.cplusplus.com/reference/vector/vector/begin/ –
Bu, 'const' ve' 'const'' aşırı yüklerinin çalışma şeklidir. Sadece 'Input' 'const' -destekse,' const' aşırı yüklenir. Ayrıca, yineleyiciyi yayınlamak yerine, şablon türünü belirtebilirsiniz: std :: mesafe (Input.begin(), itTarget) ' –