Thread: Reference another class's data member...

  1. #1
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    Reference another class's data member...

    The cpp is attached, heres the problem.

    In function User_Info i take in the users name, age and sex. These are three member functions, a string, int and char. Each returns its according variable.

    In function Greet_User i want to call in these three. I thought maybe i couldn't because they are private, but public gives me the same error. I am new to classes so please be patient. Some of the other functions are incomplete but the program will run if u remove my problem so you can ignore them. Heres the cpp.

  2. #2
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Change parameters to

    Code:
    void Hello(User_Info &User_Info);
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    now its three errors

    Code:
    --------------------Configuration: ChatBot - Win32 Debug--------------------
    Compiling...
    ChatBot.cpp
    C:\Program Files\Microsoft Visual Studio\MyProjects\ChatBot\ChatBot.cpp(117) : error C2660: 'Hello' : function does not take 0 parameters
    C:\Program Files\Microsoft Visual Studio\MyProjects\ChatBot\ChatBot.cpp(240) : error C2597: illegal reference to data member 'User_Info::name' in a static member function
    C:\Program Files\Microsoft Visual Studio\MyProjects\ChatBot\ChatBot.cpp(244) : error C2597: illegal reference to data member 'User_Info::age' in a static member function
    Error executing cl.exe.
    
    ChatBot.obj - 3 error(s), 0 warning(s)
    The first one is the call in main cuz its .hello(), what should the para's be? the same?

  4. #4
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    the arguement should be the name of the object, and use ".", not "::" to access variables
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  5. #5
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    that did it but i had to move them to public.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. How to: Use OpenGL with Jgrasp
    By Pickels in forum Game Programming
    Replies: 3
    Last Post: 08-30-2005, 10:37 AM
  4. Replies: 4
    Last Post: 06-14-2005, 05:45 AM
  5. How do I base size of arrays on annother number?
    By Dual-Catfish in forum C++ Programming
    Replies: 15
    Last Post: 09-25-2001, 01:31 PM