Jun 3, 2012 at 9:15pm Jun 3, 2012 at 9:15pm UTC
throw Ex(number);
What kind of an object is Ex? The compiler does not know, because it has never seen that kind of an object. In C++, the compiler must know about an object before you try to use it.
Ex{
If this is meant to be defining the class Ex, you need to use the class keyword.
class Ex{
Last edited on Jun 3, 2012 at 9:19pm Jun 3, 2012 at 9:19pm UTC
Jun 3, 2012 at 9:17pm Jun 3, 2012 at 9:17pm UTC
ı did definition of class for ex. I did not understand you what did you want to say sorry:(
Jun 3, 2012 at 9:19pm Jun 3, 2012 at 9:19pm UTC
can you give me an example
Jun 3, 2012 at 9:20pm Jun 3, 2012 at 9:20pm UTC
My fault; I was unclear. I meant you must tell the compiler about it (either by defining or declaring it) before you try to use it.
Jun 3, 2012 at 9:23pm Jun 3, 2012 at 9:23pm UTC
but there is no need to declare it. ı did class definition ...
how can ı do this declaration?
Jun 3, 2012 at 9:36pm Jun 3, 2012 at 9:36pm UTC
ı did class definition ...
Yes you did. Did you do it before you tried to use it? No.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
//string::find
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;
class Ex{
string j;
public :
Ex(string m){ j=m; }
void print() { cout<<j<<" sehryer is okey" ; };
};
class Ticket
{protected :
int type;
string number;
public :
Ticket(){ cout<< "enter number" <<endl; cin>>number; }
void set_number() {cout<<" enter the number of winning ticket" <<endl;
cin>>number;
} // end of set_type
string get_number(){return number;} // end of get_type
};
class Lottery:public Ticket
{
string a[35];
public :
Lottery(){ifstream read("win.txt" , ios::in);
for (int i=1; i<36;i++)
{read>>a[i];
cout<<a[i]<<endl;
}
} // end of lottery constructor
void search(){
for (int i=1; i<36; i++)
{if (a[i]==number)
{cout<<"you won" <<endl;
throw Ex(number);}
}
} // end of search function
};
int main()
{
Lottery lucky;
try
{
lucky.search();
}
catch (Ex &x)
{
x.print();
};
system("pause" );
return 0;
} // end of main;
Please do note that using exceptions instead of proper (and much simpler) function return values is expensive and generally considered bad practice.
Last edited on Jun 3, 2012 at 9:37pm Jun 3, 2012 at 9:37pm UTC
Jun 3, 2012 at 9:41pm Jun 3, 2012 at 9:41pm UTC
you can not be serious :)
this can not be such a easy :))
thanks hahha;
this is good point.... ı understood now:)
Last edited on Jun 3, 2012 at 9:42pm Jun 3, 2012 at 9:42pm UTC