SNpn
SNpn

Reputation: 2207

Error Message C++

I got this error message when trying to compile my code:

btree.h:23: error: expected unqualified-id before 'template'

it comes from this line:

template <typename T> std::ostream& operator<<(std::ostream& os, const btree<T>& tree);

there is absolutely nothing above this line except a bunch of comments and a couple of #include library files, which are:

#include <iostream>
#include <cstddef>
#include <utility>

#include "btree_iterator.h"

my btree_iterator.h holds:

template <typename T>
class btree_iterator  {


}

if someone could tell me whats wrong it'd be much appreciated!

Upvotes: 1

Views: 216

Answers (3)

Ayjay
Ayjay

Reputation: 3433

You forgot a semicolon:

template <typename T>
class btree_iterator  {


};
 ^

Upvotes: 4

vishakvkt
vishakvkt

Reputation: 864

If you are declaring it within the class, you should templatize the class itself and directly define this within it.

template<typename T>
class btree {

   //your overloaded function here without the beginning template declaration
};

Also with template classes, you cannot separate the class into a strictly header(.h) and implementation(.cpp) file because then the compiler will not be able to create the correct objects at runtime as if it can only see the header. So in the same '.h' file, write both the declaration and definition.

Upvotes: 0

Zan Lynx
Zan Lynx

Reputation: 54325

Comment that line out and put a very simple line, maybe a typedef char mychar; If you get an error on that line then you can figure out that the actual mistake is at the end of btree_iterator.h.

Because in C and C++ include files just paste the contents of the include file. If there is a typo in the include file, perhaps a missing semicolon, that carries through into the original file.

Upvotes: 0

Related Questions