member function don't pass to class!!!???
-
Hello all; I am writing a tiny phone book program using classes.
using namespace std;
class phonebook{
public :
void add_new();private : char \*name; char \*family; }; void phonebook::add\_new(){ phonebook \*temp=new phonebook; cin >> temp->name; cin >> temp->family; }
int main(int argc, char *argv[])
{
phonebook::add_new();
system("PAUSE");
return EXIT_SUCCESS;
}Any work I do; I can't get a name and family. my program should be dynamic. What should I do to get response? Thanks in advance...
-
Hello all; I am writing a tiny phone book program using classes.
using namespace std;
class phonebook{
public :
void add_new();private : char \*name; char \*family; }; void phonebook::add\_new(){ phonebook \*temp=new phonebook; cin >> temp->name; cin >> temp->family; }
int main(int argc, char *argv[])
{
phonebook::add_new();
system("PAUSE");
return EXIT_SUCCESS;
}Any work I do; I can't get a name and family. my program should be dynamic. What should I do to get response? Thanks in advance...
Since your code will not even compile successfully it is little wonder it doesn't work. You are making a static call to a non-static method (
phonebook::add_new();
), which is invalid. Try looking at your design here, every time you calladd_new()
you create a new phonebook object but you do not save it anywhere. Consider the contents of a real phonebook, the book contains entries and each entry contains names and numbers. So you need a collection of some sort to hold all your entries; this could be a class or one of the STL types. Perhaps you should try this without using classes as a first attempt to get the concepts right and then convert to classes later.Just say 'NO' to evaluated arguments for diadic functions! Ash