Like Tree1Likes

Global variable vs parameter 'sending'.

This is a discussion on Global variable vs parameter 'sending'. within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by MipZhaP The main.cpp file is responsible for creating (using OpenGL - you don't need to care about ...

  1. #16
    C++ Junkie Mozza314's Avatar
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    174
    Quote Originally Posted by MipZhaP View Post
    The main.cpp file is responsible for creating (using OpenGL - you don't need to care about that) an "aquarium" and making a list/vector of Fish objects so it can put them inside the aquarium.
    Maybe I'm missing something here, but to me the solution that jumps out is to make an Aquarium class which has the fish vector as a member and populates that vector with fish in its constructor (possibly with parameters for the number of fish and such which can be specified in main.cpp via constructor arguments).

  2. #17
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Another solution is to (from main.cpp) give a pointer to the list as a parameter to every fish so they can have a reference to it and then give that reference to the boids.cpp algorithm when it needs to use it. But this is stupid since the refence needs to go through fish.cpp - which really doesn't need that reference for itself at all.
    I suggest you post the files you use (both .h and .cpp) with just the declaration of the classes (excluding anything between brackets).
    This way you can get a better advice, since there are two separate issues.
    1) The class design
    2) The linkage of the file
    These are not necessarily linked together

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick: Alternative to using global variable
    By abrownin in forum C++ Programming
    Replies: 1
    Last Post: 05-02-2010, 04:25 AM
  2. Replies: 22
    Last Post: 11-13-2009, 04:51 PM
  3. scope of global variable vs. static
    By chiefmonkey in forum C++ Programming
    Replies: 4
    Last Post: 06-21-2009, 12:23 PM
  4. global struct variable best use
    By Kempelen in forum C Programming
    Replies: 2
    Last Post: 06-05-2009, 05:08 AM
  5. Global variable in shared library
    By krock923 in forum C Programming
    Replies: 5
    Last Post: 01-11-2008, 03:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21