1

Rather than compiling, my code is throwing the following error:

expected unqualified-id before ‘;’ token
 template std::list<SGAction_MaxMinMax>::iterator;

I've looked at other threads on similar errors, but none seem to address my problem.

//! Overloaded equality operator
/*!< Returns true if the state and action are the same. */
bool operator==(const SGAction_MaxMinMax & lhs,
                const SGAction_MaxMinMax & rhs);

//! Overloaded comparison operator.
/*!< Returns true if the lhs state is strictly less than the rhs
   state, or if they are equal and the lhs action is strictly less
   than the rhs action/ */
bool operator<(const SGAction_MaxMinMax & lhs,
               const SGAction_MaxMinMax & rhs);

template class std::list<SGAction_MaxMinMax>;
template std::list<SGAction_MaxMinMax>::const_iterator;
template std::list<SGAction_MaxMinMax>::iterator;

The error is on the second to last, and third to last, lines of code above.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Ilan Wolff
  • 23
  • 4
  • 4
    Please add some of the surrounding code for context. Is this supposed to be a declaration of a template? A specialization? Is this inside a template class or function? Your code looks wrong in any case, but the fix depends on what you're trying to do. – alter_igel Jul 09 '19 at 21:59
  • 1
    what is 'class' doing there? – Serge Jul 09 '19 at 22:03
  • Syntax looks wrong; can you please post more of the code to further assist you – Hasan Patel Jul 09 '19 at 22:07
  • This is code I cloned off github that I am working on for a professor and I'm actually not entirely sure what is going on here, but I think it is declaring a template. This is a an hpp file. Here is some more of the surrounding code for context – Ilan Wolff Jul 09 '19 at 22:16
  • Sorry, I am having trouble formatting code in the comments. I will edit the original post – Ilan Wolff Jul 09 '19 at 22:17
  • @IlanWolff thanks. Editing the original post is actually how we like to do things here, since it greatly improves the reading experience for future users. Unfortunately, this code still looks broken to me, and it's hard to tell what is supposed to happen. Is this at global scope? What comes after? It may help to link the original repository if you can, in addition to showing just a bit more context. – alter_igel Jul 09 '19 at 22:25

1 Answers1

2
template class std::list<SGAction_MaxMinMax>;

This thing is called an explicit template instantination definition. It makes the compiler instantinate std::list<SGAction_MaxMinMax>, and it causes all methods in std::list<SGAction_MaxMinMax> to be compiled, even if they aren't used.

You can read more about this rarely used feature here: Explicit instantiation - when is it used?


template std::list<SGAction_MaxMinMax>::const_iterator;
template std::list<SGAction_MaxMinMax>::iterator;

These lines don't look like valid C++ to me. It could be an attempt at explicit instantination as well (but class is missing).

GCC doesn't compile those even if you add class (because apparently list<T>::iterator and const_iterator are type aliases rather than classes).

Simply removing those two lines might work.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207