0

I am new to c++ and I am trying to create a lock free queue in c++98 using the boost library (version 1.53). When I compile my code in c++98 I get the following error:

error: ‘q’ was not declared in this scope
  boost::lockfree::queue<T *, boost::lockfree::capacity<SIZE>> q;

When I remove the capacity option (boost::lockfree::capacity) the error appears to disappear. What am I missing here and doing wrong?

The line that causes the error exists by itself within the constructor and is as follows:

    boost::lockfree::queue<T *, boost::lockfree::capacity<SIZE>> q;
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • The minimum required compiler is Visual Studio 2008 (VC++ 9.0) SP1 or another C++11 compliant. – 273K Jun 22 '21 at 06:55
  • please show a [mre] and include compiler name and version and compile options. Might just need a space in `>>` so that it's not mistaken for shift right – Alan Birtles Jun 22 '21 at 07:06
  • @AlanBirtles adding spaces appears to have fixed the error thank you. –  Jun 22 '21 at 07:19
  • Yeah. Before C++11, `std::vector>` would interpret the final `>>` as operator. You need spaces to separate them. I suppose there is a duplicate somewhere, but I cannot find it. – Yksisarvinen Jun 22 '21 at 07:42
  • 1
    @Yksisarvinen: I found [Template within template: why "\`>>' should be \`> >' within a nested template argument list"](https://stackoverflow.com/q/6695261) with google for `site:stackoverflow.com nested template ">>"`. That Q&A is so old it doesn't mention C++11, though! Ah, [For nested templates, when did \`>>\` become standard C++ (instead of \`> >\`)?](https://stackoverflow.com/q/7087033) is more recent. – Peter Cordes Jun 22 '21 at 13:24

1 Answers1

0

Before C++11, << or >> in any place (including templates argument list) would be interpreted as operator. You need to separate every bracket with a space:

boost::lockfree::queue<T *, boost::lockfree::capacity<SIZE> > q;

With C++11 or later, your original line should compile as-is.

Yksisarvinen
  • 18,008
  • 2
  • 24
  • 52