Hi Thomas, 

I looked at the code below and I can find very few problems with it
like:

1.       Not defining stu object, and unnecessary defining of stu1/2/3

2.       defining destructor inside class itself,  

3.       name and stunum should have been initialized and 

4.       main should have returned int in order to let OS know the
correct exit status of exe.

 

I would love to see if there are any other problems with this code.  So
please provide ur review comment.

 

Thanks,

Hans Raj

 

From: [email protected] [mailto:[email protected]] On Behalf
Of Thomas Hruska
Sent: Tuesday, June 09, 2009 9:31 PM
To: [email protected]
Subject: Re: [c-prog] class code example

aliyaawaispk wrote:
> #include<iostream.h>
> #include<string.h>
> 
> class student
> {
> private:
> char name[50];
> int stunum;
> public:
> 
> student();
> ~student()
> {
> cout<<"i am destructor"<<endl;
> }
> 
> void setvalue(char * );
> 
> void display();
>  
> };
> 
> student::student()
> {
> //cout<<"i am constructor"<<endl;
> strcpy(name,"\0");
> stunum=0;
> }
> 
> void student::setvalue(char * a)
> {
> strcpy(name,a);
> }
> void student::display()
> {
> cout<<name<<endl;
> }
> 
> 
> void main()
> {
> student stu1,stu2,stu3;
> stu.setvalue("aliya");
> stu.display();
> 
> }

There are a ton of problems with the code, but did you have a specific 
purpose for posting? We could nitpick this code to death if that is 
what you want. It is a good example of how one should NOT write a 
class. Plus, the code won't compile in the first place.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task. Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/




--------------------------------------------------------------------------
This message w/attachments (message) may be privileged, confidential or 
proprietary, and if you are not an intended recipient, please notify the 
sender, do not use or share it and delete it. Unless specifically indicated, 
this message is not an offer to sell or a solicitation of any investment 
products or other financial product or service, an official confirmation of any 
transaction, or an official statement of Merrill Lynch. Subject to applicable 
law, Merrill Lynch may monitor, review and retain e-communications (EC) 
traveling through its networks/systems. The laws of the country of each 
sender/recipient may impact the handling of EC, and EC may be archived, 
supervised and produced in countries other than the country in which you are 
located. This message cannot be guaranteed to be secure or error-free. 
References to "Merrill Lynch" are references to any company in the Merrill 
Lynch & Co., Inc. group of companies, which are wholly-owned by Bank of America 
Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are 
Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a 
Condition to Any Banking Service or Activity * Are Not Insured by Any Federal 
Government Agency. Attachments that are part of this E-communication may have 
additional important disclosures and disclaimers, which you should read. This 
message is subject to terms available at the following link: 
http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you 
consent to the foregoing.
--------------------------------------------------------------------------
 


[Non-text portions of this message have been removed]

Reply via email to