Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compiler error expected nested-name specifier

I am the OP for the question: Extending a class in which I received an excellent answer. However, as I try to compile the code (reworked slightly for my project) I received the following message (line no. changed to reflect following sample code):

except.h: | 09 | expected nested-name-specifier before ‘handler_t1’

along with many more which seem to stem from this line. I am brand new to C++, and my research into the answer (and the forthcoming problem) has yielded this fact: Microsoft's compiler seems to accept the code, but standards compliant ones do not.

The code as I currently have it is as follows:

#include <vector>
namespace except
{
  // several other classes and functions which compile and work already
  // (tested and verified) have been snipped out. Entire code is over
  // 1000 lines.

  class Error_Handler
  {
    public:
      using handler_t1 = bool (*)(except::Logic const&);
      std::vector<handler_t1> logic_handlers;

      // a lot more removed because the error has already happened ...
  }
}

A read through of the code in the linked question indicates to me (with my limited knowledge) that it should all work.

My question therefore is: What do I need to change in this declaration/definition to enable this to compile with gcc (4.6.3 64 bit linux compiling with -std=C++0x)?

like image 733
Jase Avatar asked Jan 11 '23 12:01

Jase


1 Answers

GCC 4.6.3 doesn't support C++11 type aliases: using handler_t1 = bool (*)(except::Logic const&);. Non-template type aliases are equivalent to typedefs: typedef bool (*handler_t1)(except::Logic const&);. Replace them and see if that helps.

Or even better, upgrade to a more recent compiler version. I believe the regular responders here tend to write to the portion of the language compiled by GCC 4.8.

EDIT: The only other iffy feature I see in that answer is range-based-for, which I believe GCC added support for in 4.6. You should be OK after replacing the type aliases with typedefs.

like image 159
Casey Avatar answered Jan 18 '23 23:01

Casey