0

This is (a small part of) my struct:

` struct BASE {

struct s
{

    //...

};


template<typename T>
struct DerivedTemplate : public s
{

    struct SW
    {
        short   ndx = 0;
        double  val = 0;
        bool    glch = false;

        SW(short ndx, double val, bool glch){this->ndx = ndx;this->val = val;this->glch = glch;}
    };

    static vector<SW> SW__BIGGR;

};

};`

Then I seek to initialize the vector "SW__BIGGR" in the following way:

template <typename T>
vector<BASE::DerivedTemplate<T>::SW> BASE::DerivedTemplate<T>::SW__BIGGR = BASE::DerivedTemplate<T>::SW(0, 0, false);

And I get this compiler error:

error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’
 vector<BASE::DerivedTemplate<T>::SW> BASE::DerivedTemplate<T>::SW__BIGGR = BASE::DerivedTemplate<T>::SW(0, 0, false);
                                         ^
[...] note:   expected a type, got ‘BASE::DerivedTemplate<T>::SW’

When I do the same operation with a vector of simple type such as "int", everything works fine. What am I doing wrong? Thank you!

EDIT:

After adding "typename" before "BASE:: ..." as I was kindly told to do in a comment, I get this error:

error: expected unqualified-id before ‘=’ token vector<typename BASE::DerivedTemplate::SW> typename BASE::DerivedTemplate::SW__BIGGR = typename BASE::DerivedTemplate::SW(0, 0, false); ^

Obviously, the vector cannot be initialized like that (as I am doing without problem with an "int" or "double" vector), but how can it?

EDIT 2:

After deleting "typename" before " ... SW__BIGGR" as kindly suggested, I now get this error for which I could not find an answer googling ("sgnl__01" is a struct based on the struct template "DerivedTemplate"):

"error: conversion from ‘BASE::DerivedTemplateBASE::sgnl__01::SW’ to non-scalar type ‘std::vectorBASE::DerivedTemplate<BASE::sgnl__01::SW, std::allocatorBASE::DerivedTemplate<BASE::sgnl__01::SW> >’ requested vector<typename BASE::DerivedTemplate::SW> BASE::DerivedTemplate::SW__BIGGR = typename BASE::DerivedTemplate::SW(0, 0, false);" Lost again :-(

Edmond
  • 1
  • 1
  • 1
    In short, the `SW` in `BASE::DerivedTemplate::SW` is a *dependent name*, so you need `typename BASE::DerivedTemplate::SW`. – Some programmer dude Jul 14 '20 at 23:09
  • Thank you! I have added "typename" before all three "BASE:: ...", and now I get this error instead: "error: expected unqualified-id before ‘=’ token vector::SW> typename BASE::DerivedTemplate::SW__BIGGR = typename BASE::DerivedTemplate::SW(0, 0, false);" – Edmond Jul 14 '20 at 23:23
  • Unlike `BASE::DerivedTemplate::SW`, `BASE::DerivedTemplate::SW__BIGGR` is *not* a dependent name, and doesn't need the `typename` prefix. – Some programmer dude Jul 14 '20 at 23:34
  • Thanks very much again! One step forward, but my cluelessness does not stop there because now I get this error: "error: conversion from ‘BASE::DerivedTemplate::SW’ to non-scalar type ‘std::vector::SW, std::allocator::SW> >’ requested vector::SW> BASE::DerivedTemplate::SW__BIGGR = typename BASE::DerivedTemplate::SW(0, 0, false);" Lost again :-( – Edmond Jul 14 '20 at 23:39
  • Sorry for being so stupid: seems the {} where missing around the right side of the assignment. – Edmond Jul 14 '20 at 23:59

0 Answers0