Help with C++ compile error

Discussion in 'C++' started by Mark, Aug 15, 2006.

  1. Mark

    Mark Guest

    Hi,

    We have a class that defines an exception:

    template <class A, class B, class C, class D > class X : public Y
    {
    ...
    class SomeException : public BaseException
    {
    ...
    }
    };

    We need to catch the exception in another class:

    template <class Dispatcher> class Something : public YetAnotherClass
    {
    Dispatcher *fDispatcher;

    void HandleMessage(...)
    {
    try {
    ...
    } catch (Dispatcher::SomeException) // This line has the error
    {
    ...
    }
    }
    ....

    [some code omitted for brevity]

    This code compiles under Sun Workshop 6 update 2 and under Compaq C++
    V6.5-004 for OpenVMS Alpha V7.3-1 but not under GNU C++ V3.3.5 and
    2.95.4 (on debian Linux).

    The error message is "parse error before ';' token" on the 'catch'
    line.

    Can anyone tell me if this is a compiler bug or is the syntax
    incorrect?

    TIA, Mark
     
    Mark, Aug 15, 2006
    #1
    1. Advertising

  2. Mark

    Rolf Magnus Guest

    Mark wrote:

    > Hi,
    >
    > We have a class that defines an exception:
    >
    > template <class A, class B, class C, class D > class X : public Y
    > {
    > ...
    > class SomeException : public BaseException
    > {
    > ...
    > }
    > };
    >
    > We need to catch the exception in another class:
    >
    > template <class Dispatcher> class Something : public YetAnotherClass
    > {
    > Dispatcher *fDispatcher;
    >
    > void HandleMessage(...)
    > {
    > try {
    > ...
    > } catch (Dispatcher::SomeException) // This line has the error


    } catch (typename Dispatcher::SomeException)

    > {
    > ...
    > }
    > }
    > ...
    >
    > [some code omitted for brevity]
    >
    > This code compiles under Sun Workshop 6 update 2 and under Compaq C++
    > V6.5-004 for OpenVMS Alpha V7.3-1 but not under GNU C++ V3.3.5 and
    > 2.95.4 (on debian Linux).
    >
    > The error message is "parse error before ';' token" on the 'catch'
    > line.
    >
    > Can anyone tell me if this is a compiler bug or is the syntax
    > incorrect?


    I think the syntax is correct, but not the semanctics. SomeException is a
    name dependand on a template argument. In such a situation, you have to
    explicitly tell the compiler that it's a type, otherwise it is required to
    assume that it's a value.
     
    Rolf Magnus, Aug 15, 2006
    #2
    1. Advertising

  3. Mark

    Greg Guest

    Mark wrote:
    > Hi,
    >
    > We have a class that defines an exception:
    >
    > template <class A, class B, class C, class D > class X : public Y
    > {
    > ...
    > class SomeException : public BaseException
    > {
    > ...
    > }
    > };
    >
    > We need to catch the exception in another class:
    >
    > template <class Dispatcher> class Something : public YetAnotherClass
    > {
    > Dispatcher *fDispatcher;
    >
    > void HandleMessage(...)
    > {
    > try {
    > ...
    > } catch (Dispatcher::SomeException) // This line has the error
    > {
    > ...
    > }
    > }
    > ...
    >
    > [some code omitted for brevity]
    >
    > This code compiles under Sun Workshop 6 update 2 and under Compaq C++
    > V6.5-004 for OpenVMS Alpha V7.3-1 but not under GNU C++ V3.3.5 and
    > 2.95.4 (on debian Linux).
    >
    > The error message is "parse error before ';' token" on the 'catch'
    > line.


    The error is probably a missing "typename" keyword. I would change the
    catch line to read:

    catch (typename Dispatcher::SomeException)

    Greg
     
    Greg, Aug 15, 2006
    #3
  4. Mark

    Mark Guest

    On 15 Aug 2006 03:21:33 -0700, "Greg" <> wrote:

    >The error is probably a missing "typename" keyword. I would change the
    >catch line to read:
    >
    > catch (typename Dispatcher::SomeException)


    Thanks Rolf and Greg, that has solved it :)

    Mark
     
    Mark, Aug 15, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nagaraj
    Replies:
    1
    Views:
    901
    Lionel B
    Mar 1, 2007
  2. timjowers
    Replies:
    7
    Views:
    4,401
    heyjude
    Feb 2, 2011
  3. Replies:
    1
    Views:
    462
    Cowboy \(Gregory A. Beamer\)
    Apr 11, 2008
  4. Carter
    Replies:
    2
    Views:
    524
    Carter
    Mar 4, 2009
  5. fAnSKyer
    Replies:
    2
    Views:
    557
    Alf P. Steinbach
    Jun 7, 2009
Loading...

Share This Page