Access variable inside class from other class
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Access variable inside class from other class

  1. #1
    Join Date
    Nov 2013
    Posts
    3

    Talking Access variable inside class from other class

    Hello,

    I am trying to access a variable from another class through another class but it is not returning its "instance"?
    Example:
    Class View
    Code:
    ...
    V3D_Viewer viewer;
    ...
    Class MainWindow
    Code:
    ...
    viewer* myView;
    myView = new viewer();
    ...
    Class Test
    Code:
    ...
    MainWindow window;
    window.myView->setBackgroundColor(WHITE);
    ...
    I am new to c++ references and pointers,
    can someone help me out?

    thanks

  2. #2
    Join Date
    Nov 2013
    Posts
    3

    Re: Access variable inside class from other class

    Edit:
    Class Test
    Code:
    ...
    MainWindow window;
    window.myView->viewer
    ...

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,958

    Re: Access variable inside class from other class

    Code:
    ...
    // MainWindow.h
    class MainWindow
    {
    ...
    public:
        V3D_Viewer* myView;
    ...
    };
    
    // MainWindow.cpp
    MainWindow::MainWindow()
    {
    ...
        myView = new V3D_Viewer();
    ...
    }
    ...
    // somewhere in other .cpp
    window.myView->setBackgroundColor(WHITE);
    Best regards,
    Igor

  4. #4
    Join Date
    Nov 2013
    Posts
    3

    Re: Access variable inside class from other class

    Thank you Sir!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center