Solved

C++ Builder5 exception problem

Posted on 2002-07-01
3
199 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now