tags:

views:

352

answers:

6

I don't understand what is wrong with this code.

gcc reports "Client.h:29: error: expected template-name before '<' token"

As far as I'm aware I'm followed the template syntax correctly, but it could be that the error message is confusing me and is not the problem

client.h

class Client : public BaseDll<DllClient> [line 29]
{
..snip..
};

basedll.h

template<typename T>
class BaseDll : public Base
{
public:
    ..snip..

private:
  T* _dll;
};
+1  A: 

Maybe it's just an easy problem: Have you included basedll.h in client.h?

sth
wouldn't that've meant that he would've gotten an error earlier on though?
Dasuraga
Hmm, well, was worth a shot since the rest of what you posted looks alright.
sth
A: 

I think you snipped away the problem. Are you including something to define 'DllClient' ?

Kieveli
yes DllClient's header is included in client.h. I will make a point of posting better code examples next time, sorry to everyone..
Even still - you can boil it down to a simpler example to try to root out the issue. Add a few lines to make an example that still breaks. If it doesn't break any more, start adding in pieces until it does - then you'll probably know your solution ;)
Kieveli
+1  A: 

to cover the basics:

does client-h #include basedll.h? do they user different include guards?

Further troubleshooting: does it work with a non-template base class? does it work then you typedef the template instaltiation:

typedef BaseDll<DllClient> tClientBase;
class Client : public tClientBase { ... }

[edit] OK, next:

if you put the following two lines directly under the BaseDll declaration:

template <typename T>
class BaseDll
{ ... 
};
class DummyFoo;
typedef BaseDll<DummyFoo> tDummyFoo;
peterchen
hi.yes client.h includes basedll.h which contains include guardsI tried with the typedef, error message with that new linw is: "error: expected initializer before '<' token"
+2  A: 
class Base{
};
template<typename T>
class BaseDll:public Base{
public:
private:
T* _dll;
};
class DllClient{
};
class Clien:public BaseDll<DllClient>
{
};

this compiled for me without problems, so I don't think the problem lies within what you posted. My best bet would be that you made a syntax error in client.h, maybe something as simple as forgetting a semicolon after another class definition or some macro that's messing with your code

Dasuraga
DllClient (a Dll/so wrapper) inherits DllAddon<DllAddonInterface> (where the wrapping takes place) which does use macros now you mention it. I will look again and see if the problem is there.(can't see any missing semicolons for now)
A: 

A possible cause of this is that there is an inter-dependency between the different header files:

// client.h
#ifndef CLIENT
#define CLIENT

#include "base.h"

// ... 

class Client : public BaseDll<DllClient>
{
  // ..snip..
};

#endif


// base.h
#ifndef BASE
#define BASE

#include "client.h"

template<typename T>
class BaseDll : public Base
{
public:
  // ..snip..

private:
  T* _dll;
};

#endif

Now imagine we're parsing 'base.cpp' then the preprocessor will do the following:

#include "base.h"
#ifndef BASE        <--- BASE unset, keep going
#define BASE
#include "client.h"
#ifndef CLIENT
#define CLIENT
#include "base.h" 
#ifndef BASE        <--- BASE set, skip base.h, return to client.h
class client
 : public BaseDll<DllClient>  <-- ERROR, BaseDll not defined.

If this is the problem, then you potentially can get around it by forward declaring the base template in client.h:

// client.h
#ifndef CLIENT
#define CLIENT

// #include "base.h"    <-- remove include
template <typename DLL_CLIENT>
class BaseDll;

// ... 

class Client : public BaseDll<DllClient>
{
  // ..snip..
};

#endif
Richard Corden
+2  A: 

I'm so sorry everyone, a school-boy error has been made, BaseDll is declared in another namespace. As soon as I added the namespace qualifier, the problem has gone.

happens to the best of us :P
Dasuraga
thanks for understanding :)