If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > c++ class problems

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-25-09, 22:41
DaveMason DaveMason is offline
Registered User
 
Join Date: Mar 2009
Posts: 8
c++ class problems

Hello!
Can someone help with this simple class. I'm getting a bunch of errors. What am I doing wrong?

thanks,
Dave
-------------
//Student.h
class Student
{
public:

//initialize default constructor
Student(const char ln[]="",const char fn[]="", int a[]=0);

void setLastName(const char ln[]);
void setFirstName(const char fn);
void setAge(int a[]=0);

const char getLastName() const;
const char getFirstName() const;
int getAge() const;

private:
char lname[25]; 25 characters max for last name
char fname[25]; 25 characters max for first name
int age[3]; 3-digit max for age
}

//Student.cpp
//default constructor
Student:tudent(const char ln[], const char fn[], int a[])
{
setLastName(ln);
setFirstName(fn);
setAge(a);

}

void Student::setLastName(const char ln[])
{
if (lname != NULL) //if last name has garbage
delete[] lname; //clear it

lname = new char[strlen(ln)+1];
assert (lname != NULL);
strcpy (lname, ln);
}

void Student::setFirstName(const char fn[])
{
if (fname != NULL) //if first name has garbage
delete[] fname; //clear it

fname = new char[strlen(fn)+1];
assert (fname != NULL);
strcpy (fname, fn);
}


void Student::setAge(int a)
{
age=a;
}


const char Student::getLastName()const
{
return lname;
}
const char Student::getFirstName()const
{
return fname;
}

int Student::getAge()const
{
return age;
}
Reply With Quote
  #2 (permalink)  
Old 04-26-09, 02:24
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,243
It does help if you provide details of the errors......
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 04-28-09, 02:38
DaveMason DaveMason is offline
Registered User
 
Join Date: Mar 2009
Posts: 8
after 3 long hours of frustration, i finally got it to compile without errors.

thanks again for the reply.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On