Solved

Passing a struct from 1 C++ Class file to a second C++ Class File

Posted on 2008-10-07
3
306 Views
Last Modified: 2010-04-21
I have this struct

typedef struct                                          // Create A Structure For Star
{
      int r, g, b;                                    // Stars Color
      GLfloat dist;                                    // Stars Distance From Center
      GLfloat angle;                                    // Stars Current Angle
}
stars;                                                // Structures Name Is Stars
stars star[num];                                    // Make 'star' Array Of 'num' Using Info From The Structure 'stars'

which is is the main.cpp file but declared before methods open, and it is altered in the main.cpp, and i want it passed through this line

OnTimer(hDC, texture, loop, num, zoom, tilt, spin); which calls the graphics.cpp file and runs the Ontimer Method,

i also have this declared at the top of the main.cpp file

void OnTimer(HDC hDC, GLuint texture[], GLuint loop, int num, GLfloat zoom, GLfloat tilt, GLfloat spin);                           // Draw OpenGL Scene

as you can see its a OpenGL program which i am trying to create and i just want to pass the struct of veriables from the main.cpp to the graphics.cpp so i can reuse the main.cpp and all i need to do is alter the graphics.cpp file to get a different output of the screen but i cant figure out how to pass the struct from 1 file class t oa second file class
0
Comment
Question by:jjthorne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 22657631
First of all, you'll need to place the definition of the struct in a header file (.h file) :

        typedef struct                                          // Create A Structure For Star
        {
              int r, g, b;                                    // Stars Color
              GLfloat dist;                                    // Stars Distance From Center
              GLfloat angle;                                    // Stars Current Angle
        }
        stars;                                                // Structures Name Is Stars

This header file can then be included in every .cpp file that needs to use the struct.

Second, you'll want to define the global array of these structs in one of the .cpp files :

        stars star[num];                                    // Make 'star' Array Of 'num' Using Info From The Structure 'stars'

If this global array needs to be available in another .cpp file, then you'll need to add this to that other .cpp file :

        extern stars star[num];

which makes the array available for use in that other .cpp file.
0
 

Author Closing Comment

by:jjthorne
ID: 31503755
ah right yeah, im just getting back into c++, i have been programming in c# and java for the past 4 years, and i decided last weeks to try and get back into C++ and openGL, cheers for the help.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22657716
Glad to be of assistance. Do not hesitate to ask for clarifications if there are further problems/questions about this.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question