views:

108

answers:

1

Hi All,

I am getting an "Expected class-name before , or ; and I dont quite get how to fix it.

Here is where the error is:

class FXHost : public CPLAT::CP_Application, public CPLAT::CP_M_Listener 
{

The file is FXHost.h and CPLAT:: is obviously a namespace where CP_Application and CP_M_Listener are.

I dont see why this would be wrong. This code ran fine in Metrowerks (without the CPLAT::) but in XCode CPLAT is needed due to the way the code was written by the previous developer.

Can anyone shed some light on this error?

UPDATE: Here is a sample of the CP_Application class

template <class DOC_POLICY, class PRINT_POLICY, class UNDO_POLICY>
class CP_EXPORT CP_Application : public CP_Application_Imp
{
    public:
    typedef DOC_POLICY                  DocPolicyType;
    typedef PRINT_POLICY                PrintPolicyType;
    typedef UNDO_POLICY                 UndoPolicyType;

    CP_Application();
    virtual                 ~CP_Application() throw();
+2  A: 

It looks like the compiler hasn't seen the class declaration for the two parent classes. The first thing I would check are your include directives. Are you sure you're including header which defines the classes CP_Application and CP_M_Listener?

acanaday
@acanaday - That was part of it. I added CP_Application and CP_M_Listener, but it still complains about CP_M_Listener. I looked at that header and CP_M_Listener() contructor is protected. Why would you have a protected constructor? Is that my issue?
Elliot
@Elliot - The purpose of making a constructor protected is so that only derived classes (or static class methods) may invoke it (i.e. preventing direct instantiation of the class). This is typically the case with abstract base classes or singletons (more typically, private constructors). This, in itself, should not be causing compiler errors. What error are you getting now?
acanaday
@acanaday - My exact error now is: error: expected class-name before ',' token --
Elliot
@Elliot - It looks like the problem is `CP_Application`, not `CP_M_Listener`. The expected class-name before ',' token indicates that the compiler still hasn't seen the declaration for `CP_Application` and is therefore choking on an unknown symbol appearing where it is expecting a class name (specifically between `public` and the comma).
acanaday
@acanaday - hmm, CP_Application is included and that is indeed the class name.....
Elliot
@acanaday - I posted a sample above about the CP_Application class. Do you have more thoughts? I am stumped.
Elliot
*Aha!* The problem is that `CP_Application` is a template class. When `FXHost` inherits from `CP_Application` you need to specify the template parameters for `DOC_POLICY`, `PRINT_POLICY`, and `UNDO_POLICY`. Strictly speaking, `CP_Application` is not a class in and of itself, hence the error. You need to qualify it using `CP_Application<SomeDocPolicy,SomePrintPolicy,SomeUndoPolicy>` where the `Some...Policy` names here are types that implement the interface expected by the template class parameters. Only then will you be specifying the *actual class* to inherit from. Does this make sense?
acanaday
@acadaday - Yup, wow, I hate templates. Thank you, this really helps me with porting this code!
Elliot