What should I do if ma compiler says undefined symbol try during exception handling??
There are a few things wrong with that code, so let's go through them one by one: - If you want to use cin and cout without adding the namespace to every call (which would be std::cin and std::cout) you'll have to use that namespace by adding
after your imports
- You define a function inside the try block. That is not possible in C/C++; but as you have a prototype at the top, you can add it right at the bottom of the code.
- Instead of defining the check-function in that catch block you probably want to call
- You can't throw a class but you can throw an instance of a class. So instead of
you probably want
Btw, please use [CODE] tags when posting code. It makes it much easier to read.
8 1495
Probably you should show us the code. You could also check this old thread where someone had the same problem. It might help.
I remember doing something like that. In my case I used a variable from inside the catch block that was defined in the try block. The try block is out of scope when the catch block starts so the variable was undefined. All I had to do was define the variable outside the try block and everything worked.
- #include<iostream.h>
-
#include<conio.h>
-
void check(int ,int,int);
-
class e1{};
-
class day
-
{
-
private:
-
int date,month,year;
-
public:
-
void getdata()
-
{
-
cout<<"Enter date,month,year\n";
-
cin>>date>>month>>year;
-
}
-
void display()
-
{
-
cout<<date<<"/"<<month<<"/"<<year;
-
}
-
void get()
-
{
-
check(date,month,year);
-
}
-
};
-
void main()
-
{
-
day d;
-
d.getdata();
-
try
-
{
-
void check(int d1,int m1,int y1)
-
{
-
if(d1>31||m1>12||y1>13)
-
{
-
throw e1;
-
}
-
}
-
}
-
catch(e1)
-
{
-
cout<<"Invalid";
-
}
-
d.display();
-
getch();
-
}
There are a few things wrong with that code, so let's go through them one by one: - If you want to use cin and cout without adding the namespace to every call (which would be std::cin and std::cout) you'll have to use that namespace by adding
after your imports
- You define a function inside the try block. That is not possible in C/C++; but as you have a prototype at the top, you can add it right at the bottom of the code.
- Instead of defining the check-function in that catch block you probably want to call
- You can't throw a class but you can throw an instance of a class. So instead of
you probably want
Btw, please use [CODE] tags when posting code. It makes it much easier to read.
if i want to code this program in linx environment how should i compile and run this???
thanks alot....I got the output...
I assume then, that the question of how to compile and run it is answered?
yes... i tried and succeeded
Sign in to post your reply or Sign up for a free account.
Similar topics
by: pervinder |
last post by:
Hi,
I have a c++ application which depends on some other libs which uses stlport
When i build the application, it works fine on sun/linux/hp platform.
(provided the .a for the dependency libs)
...
|
by: John Graat |
last post by:
Hi all,
I've built the STLport-462 library on AIX-4.3.3 using gcc-3.3.2.
No errors during compilation. However, during linking the following
error occurs:
ld: 0711-317 ERROR: Undefined symbol:...
|
by: eugene |
last post by:
I'm trying to compile and run some c++ code to be called from Matlab
(mex file)
and I'm getting "Invalid MEX-file ... undefined symbol" error. Anybody
knows
where to look for solution?
>>mex...
|
by: r.nikhilk |
last post by:
Hi,
We are porting C++ applications from 32 bit to 64 bit on AIX platform.
(The current version of AIX is 5.3 and xlC verison is 8.0). We are able
to compile the applications by including the...
|
by: Kenneth Kahl |
last post by:
Hello,
I would like to call a C++ programm out of Java with help of JNI. By the
followed command I created a "shared library":
g++ -shared -o libcalculate.so rechner.cpp
When I create an...
|
by: pavan734 |
last post by:
Hello,
Please excuse me as Iam not posting this to correct group. I
have a parser code obtained from flex command. I have many other files.
When I compile them Iam getting a message like:...
|
by: yamitmehta |
last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my
board i get the follwing undefined symbols:-
Cpool and Csingleton are template classes. CPool has the static member...
|
by: Justin Johnson |
last post by:
Hello,
I'm trying to build Python 2.5.0 on AIX 5.3 using IBM's compiler
(VisualAge C++ Professional / C for AIX Compiler, Version 6). I run
configure and make, but makes fails with undefined...
|
by: sdeathstar |
last post by:
I am working on IBM AIX machine and using XLC C++ complier version 8.0.
1) Able to compile the objects on AIX from C and C++ source code.
2) Able to create the libraries (combination of C & C++,...
|
by: Michel Esber |
last post by:
People,
Environment: Linux AS4
I have just installed db2 v9.5 + Fixpak 2 on a machine that has db2
v8 up and running, but I am unable to create and instance:
# ./db2icrt -a SERVER -p...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |