Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Help with C++ compile error

Reply
Thread Tools

Help with C++ compile error

 
 
Mark
Guest
Posts: n/a
 
      08-15-2006
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

 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      08-15-2006
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.

 
Reply With Quote
 
 
 
 
Greg
Guest
Posts: n/a
 
      08-15-2006

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

 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      08-15-2006
On 15 Aug 2006 03:21:33 -0700, "Greg" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compile directive for conditional compile for Java 1.4 versus Java 5 timjowers Java 7 02-02-2011 12:08 AM
How to compile the following source code in VC6// I have error inVC++6 but compile ok in GCC fAnSKyer C++ 2 06-07-2009 07:57 AM
computation at compile time i.e. compile time functions usingtemplates Carter C++ 2 03-04-2009 06:43 PM
Compile versus not compile (VS 2005)?? stupid48@gmail.com ASP .Net 1 04-11-2008 08:24 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM



Advertisments