Hello,
I faced a problem to use a function in struct format. If I insert the data to the Contact("Ada", "ada@ust.hk", "12345678")). How can I print it out by using the Contact class member "print"? Thank you.
typedef struct DLL_node {
DLL_node *prev;
DLL_node *next;
Contact *contact;
} DLL_node;
class Contact {
public:
// Default constructor
Contact() {
strcpy(name, "no name");
strcpy(email, "nosuchperson@ust.hk");
strcpy(phone, "12345678");
};
// Parametric constructor
Contact(char* n, char *e, char *p) {
strcpy(name, n);
strcpy(email, e);
strcpy(phone, p);
};
// Destructor
~Contact() { /* Do nothing */ };
// Getter
char* getName() { return name; }
// Getter
char* getEmail() { return email; }
// Getter
char* getPhone() { return phone; }
// Setter
void setName(const char* n) { strcpy(name, n); }
// Setter
void setEmail(const char* e) { strcpy(email, e); }
// Setter
void setPhone(const char* p) { strcpy(phone, p); }
// Display content
void print() {
cout << " Name: " << name << endl;
cout << "email: " << email << endl;
cout << "Phone: " << phone << endl;
}
private:
char name[30];
char email[30];
char phone[10];
}; // end of Contact class definition
#endif