0

i am struggling with an error which i get when trying to compile my C++ Programm which is using templates and typenames. Here is the Code which i have problems with:

template <typename Key, size_t N = 10>
class ADS_set {
public:
class Iterator;
using key_type = Key;
.
.
.
private:
std::pair<Iterator, bool> next_idx(Bucket &bkt, const_reference key, bool split);

}; // End of class
template <typename Key, size_t N>
std::pair<ADS_set<Key, N>::Iterator, bool> ADS_set<Key, N>::next_idx(Bucket &bkt, const_reference key, bool split) {

No, the problem lies on the definition of my next_idx Method. Somehow i do not define the template parameters of my std::pair correctly as far as I do understand. I would ask you if you could provide me a correct solution and an explanation why this was wrong so that i could possibly understand this better in the future!

The error(s) which i get do say the following:

ADS_set.h:428:42: error: type/value mismatch at argument 1 in template    parameter list for ‘template<class _T1, class _T2> struct std::pair’
std::pair<ADS_set<Key, N>::Iterator, bool> ADS_set<Key, N>::next_idx(Bucket &bkt, const_reference key, bool split) {
                                      ^
ADS_set.h:428:42: note:   expected a type, got ‘ADS_set<Key, N>::Iterator’
ADS_set.h:428:44: error: prototype for ‘int ADS_set<Key,  N>::next_idx(ADS_set<Key, N>::Bucket&, ADS_set<Key, N>::const_reference, bool)’   does not match any in class ‘ADS_set<Key, N>’
std::pair<ADS_set<Key, N>::Iterator, bool> ADS_set<Key, N>::next_idx(Bucket &bkt, const_reference key, bool split) {

Thanks a lot for you help!

  • 1
    Try `typename ADS_set::Iterator` instead. – songyuanyao Jun 15 '18 at 10:11
  • Thanks a lot , that worked out! But why do i neet to specify typename again? I was thinking the compiler knows what "Iterator" is specified for and which type it is. – Stefan Padu Jun 15 '18 at 10:22
  • You have to tell the compiler that it refers to a type but not something else like a static data member. Read the duplicate post for more. – songyuanyao Jun 15 '18 at 10:41
  • @Stefan - currently the standard requires this, as there just *could* be specializations of the class where `Iterator` is not a type. However, there are thoughts of removing the restrictions in places where a type is the only possibility, see [Down with `typename`!](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0634r2.html) – Bo Persson Jun 15 '18 at 10:52

0 Answers0