Solved

C++ Builder5 exception problem

Posted on 2002-07-01
3
205 Views
Last Modified: 2011-04-14
#include <exception>

class FooException: public exception
{
   FooException() {};
};

And compiler says:

[C++ Error] File1.cpp(4): E2303 Type name expected

What's wrong? Under GCC it went just fine..
0
Comment
Question by:Robson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 7122126
Use either

#include <exception>

class FooException: public std::exception
{
  FooException() {};
};


or

#include <exception>

using namespace std;

class FooException: public exception
{
  FooException() {};
};

The compiler does not know about 'exception', as it is a member of the 'std' namespace, so you either have to use scope resolution ('std::') or refer to the namespace you want to use.
0
 
LVL 4

Author Comment

by:Robson
ID: 7122260
I knew nothing about namespaces before, thanks!

I wonder if this piece of code will compile under GCC now...
0
 
LVL 86

Expert Comment

by:jkr
ID: 7122341
>>I wonder if this piece of code will compile under GCC now...

It should - if you have an up-to-date STL version
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question