I see many time where static data member is used to count creations of objects -
i.e.
1. the static data member is init to 0
2. the static data member is incremented by 1, in the Class' constructor, every time an object is created
However, if you define a global object of a class,
How can you tell that the static data member is initialized BEFORE the constructor of the global object is called? (i.e. before the global object is created).
Because to my understanding, you do not know in advance the order of global objects' creation -
so the Global Object could be created BEFORE the static data member was created and initialized.
I have an assignment that asks me to implement a variant of the classic bouncing balls program.
'Each ball should start off at the top of the screen with a random speed in the x direction. Whenever a ball hits a screen boundary it should bounce off at an angle equal to the impact angle and lose some speed. Eventually each ball should come to a rest at the bottom of the screen. Five seconds after coming to a rest a ball should be removed from the screen.'
'Your code must keep track of objects (balls) by placing the object data structures in a linked list. You need to create your own linked list implementation. Below is a brief description of the object programming interface: CreateObject - Create a new object. The function accepts as input parameters a pointer to the SDL screen, a pointer to a model triangle array, and a variable telling the size of the model triangle array. The function returns a pointer to a new object data structure. The model triangle array specified as input parameter should not be shared across objects. (Not sharing the model triangle array allows e.g. objects to have different colors.)
Perform the necessary memory allocation and copying.DestroyObject - Free object. The function accepts as input parameters a pointer to an object data structure. The function should free all memory allocated to represent the object (memory allocated for the model triangle array and the object data structure itself).
Drawobject - Draw object on screen. The function accepts as input parameters a pointer to an object data structure. The function must draw the object on the screen by calling DrawTriangle on each of the model triangles. Remember to update scale, translation, etc., in each triangle data structure before invoking DrawTriangle.
Hint: Do not make the bouncing algorithm too complex. Bouncing a ball off a vertical or horizontal surface can be accomplished without resorting to calculating impact angles.'
The function I'm stuck at, is the first one - createobject.
I'm working on a grocery store inventory project. One part is to have a shopping cart, where customers can put in up to 20 items. Because there can be up to 20 shopping carts at one time, I want to use a vector inside the cart object to represent all the individual food items.
Here's my code,
Header:
#ifndef CART_H #define CART_H #include <vector> class Cart { public: Cart(); Cart(std::vector< int >, std::vector< int >)
I have a school project in which need to create a function that takes a File Object as a Reference Parameter. Supposedly, it should allow me to read the first piece of data from others separated by a space from a file. The later be able to continue reading from the next piece of data.
I know how to set things up to read from the data file, such as using
will copy constructor does object initialization using another already created object? I understand that it can be applied for object initialization and not for assignment.Is it correct?
I have a method to take a Tile object and make an instances of it based on some data from the original object. Than it is suppose to manipulate the a specific instance and save the results. The first loop through it works but it changes all instance as well as the base.
public static int recurse(int count, Tile[,] b,Huristic h,int check) { if (check==1) { boardState.Add(B)/>; return check; } if (check == 0)
this function will return a temporary integer now void fun1(const int & num); this function can receive from myfun().BUT void fun2(int & num); this function cannot receive from myfun() Why is that, Moreover what is lifetime of a temporary object like one returned in myfun() ???
I am using the above code to retrive an item selected by user,But this line is giving an exception "Null Reference Exception, Object reference not set to an instance of an object"
I have made an application and I have basically solved everything. But the only problem is that I am using global variables because it felt like the smoothest, so my program is built on it.
But now I've read around and I understand that you should not use these(?). Do you think pointers is the best think to use instead?I have previously declared my board array and some variables as global and I want them in alot of functions.I have read and understand the procedure for the use of pointers so I can use my int's in the other functions by doing like this? Code: #include <stdio.h>
int justprint(); int main() { int Row = 2; int Column = 2; int *pRow = &Row; int *pColumn = &Column; [code]...
But how do I do it with an array like this one? If I declare it in the main function, and then want to use it in other functions.Or are there better, easier solutions?
On linux, I can compile DLLs (shared objects) as well as executables that use them. I can even access globals and classes that are defined in the EXE from the DLL, and vice versa, simply with the 'export' keyword. flawlessly.
The Problem: But on Windows (using MinGW), no matter what I do, I'm completely unable to access global variables which defined in the EXE, from the DLL. On Linux, this is no sweat, but what's Windows' problem?
I also need to extend classes in the dll with base class method definitions defined in the exe.
Ive heard that on Windows, you need to use declspec(dllimport) and declspec(dllexport). I can compile with CygWin+MinGW/g++4.5.3 as well as "Pure Windows" with MinGW/g++4.7.2 *without* the declspecs. So what's the decljunk for? Is this really just something for MSVC or other compilers?
Here's some Windows code to show what the problem is. The DLL's global variable is accessible to the EXE just fine, but the EXE's global variable is not accessible to the DLL - compilation complains it is an undefined reference.
main.cpp #include "myLib.h" #include <stdio.h> int exe;
[Code].....
edit: I tried using --enable-runtime-pseudo-reloc --allow-shlib-undefined options when compiling the DLL and G++ complains that --allow-shlib-undefined is an unrecognized option.
I am using VS2010 to develop an app which includes several windows forms that I am trying to set up global variables for, and I am getting a few errors like:
LNK2005: "wchar_t *dsn"...already defined in ....obj
I have a header file (externals.h) with: #ifndef MY_GLOBALS_H #define MY_GLOBALS_H extern long dbg; extern wchar_t dsn[50]; extern wchar_t u[30]; extern wchar_t p[30]; #endif
and 2 different forms, each with different namespaces, but both including the above header (#include "externals.h").One of the form .h files defines the values for these externally declared variables like this: namespace PWValidationTools{
public ref class ValidationSetupForm : public System::Windows::Forms::Form { }
The other form file only uses these variables, never defines them.I am getting the above LNK2005 error only for the variables declared as wchar_t, not the "long" one. why I'm getting the link errors only for the wchar_t variables.
I created a WinForm app in C# using VS 2013 Express.
I added code to create a Global Hot Key on the main form. This works fine. My hot key is Ctrl-T. I can press the hot key and make the main form show and hide.
Then I created a second form (ChecklistForm) and now I want to press ctrl-T and make that form show and hide. I do not need the main form to do this any more. I just used the main form to test my Global Hot Key code.
So I'm having trouble getting the second form to respond to the hot key. When I put a break on the WndProc(), there is no break.
namespace ChecklistFSX { public partial class MainForm : Form { [DllImport("user32.dll")] public static extern IntPtr FindWindow(String sClassName, String AppName); private IntPtr thisWindow; private GlobalHotKeys hotkey; public MainForm()
function fun recieves the address(which is NULL) and then allocates the memory for the Box; Let's say I cannot return the address of new allocated p and I can't also use that pointer p(from main) without passing it into a function.
Q: How can I make it that I could operate in function "fun" as I operate on orginal pointer p(from main), right now I'm just passing the address to my function but I can't change the 'global' pointer p ;(.
I remember in pascal it's like: "function(var pointer:[pointer to sth])" and all is done.
I am having trouble updating my global pointer in the following code,
Code: #include <iostream> using namespace std;
struct RB{ RB()=default; RB(int clr):color(clr) { } int color;
[Code] ....
The problem is, at line where I compar y==Tnil, It is evaluating to false at the first insert. But It should be true. again, after ending the function, T again becomes equal Tnil, as a result , none of the is being inserted.