Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. member function don't pass to class!!!???

member function don't pass to class!!!???

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hasani2007
    wrote on last edited by
    #1

    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...

    L 1 Reply Last reply
    0
    • H hasani2007

      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...

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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 call add_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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups