Thread: accessing a object that you don't know

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    18

    accessing a object that you don't know

    Programming with msvc++6, using win32 console app.

    Here is my deal.

    I am making a menu class so i can easily and quickly insert menus into the programs I make. Have it set up now so I can add a menu to a program with little code (How many items you want to be listed is n, you only have to code n+1 lines. very simple).

    You navigate this menu using your arrow keys and select an item by pressing the enter key. Pretty basic setup. Now here is my problem.

    I have a class called menu, and a class called menunode. Menu node exisits for each entry in the list. Its members:
    Code:
    int value // holds the place in the list (between 1-last item)
    string title // the actual name of the item
    and the functions needed to access and alter those items.

    Now, the other class, menu, uses a binary search tree as a base and has data members of interest are:
    Code:
    int selection
    now, what i want to do. Is print the title of the node a special way if the value currently at in the list (held by selection) is the same as the value of the node.

    So, enough of the confusing background, can I get menunode the ability to access the variables of functions in menu without having an object?

    Here is a little tree:

    menu calls the print function of my binary search tree which calls the print function on the menunode.

    Can i let my print function in menunode access the functions in menu?

    thanks
    cow

  2. #2
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Do you mean this?

    Can i let my print function in menunode access the functions in menu?
    Do you mean something like this ...

    cout << print(menu());

    Yes, you can do that but you may have to list the parameters within the menu function.
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    18
    not exactly.

    The menu class holds which item the user is currently at (ie, first item in the list, var is 1. second item, var is 2. etc

    Now, when printing each node (menunode object), i want it to check to see if it is infact that special item. so it would have to be something like:

    Code:
    if(menunode.getValue()==menu.getSelection())
    that is a crude example of testing to see if the value of the node is the same as value of the current selection in the menu. However, here is the problem. I can't pass the selection value to the node. If i could pass the value, i would just call print(int value) and allow the variable to be passed down to the node level and then have it checked. But that is not an option. I am using a virtual print function that takes no parameters, and there is no chance of changing it.
    cow

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, given the limitations, it doesn't look promising It sounds like your only options are
    1) a global variable.
    2) well, ok, that was it

    Why can't you pass it a value? Is it a third party function?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Base-class pointer, accessing object from derived class
    By Korhedron in forum C++ Programming
    Replies: 15
    Last Post: 09-28-2008, 05:30 AM
  2. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  3. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  4. Object array. Probelm accessing methods
    By Bean in forum C++ Programming
    Replies: 4
    Last Post: 05-03-2004, 11:22 AM
  5. Accessing the C++ Standard Library locale object
    By Davros in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2003, 10:18 AM