@firedraco, i have declared and initialized the object in the source file. i did not get the error more by linking. but when i execute the program it will be broken directly. it throws "segmentation error". So how can i declare the object "Test" in the best way?
I would declare it as a global object (assuming you really want it to be global). With that, you won't be able to have a member function reference that though. I have a question though, why do you need a member function that needs a random global variable? Could you pass it as a parameter or something instead?
@firedraco. you are right. but sometimes you get some application from someone else and you are not allow to modify for example some interface function. therefore you may need what i need now :)
So, how can i implement this object as a global object? and what you mean with "you won't be able to have a member function reference that though."??
I'm not sure I understand what you are trying to do then...what exactly is this member function supposed to be doing? Member functions shouldn't need global variables to exist, they should be dependent on the whatever object they are modifying (unless they are static, but they still shouldn't need global variables).
@firedraco. I do not know which member functions do you mean. But let us consider the above case again after ihave modified the code
I want to call the foo() function from file2.cpp. This foo() function is and implemented in the file1.cpp. but it is not a member function of the class cl1.
The problem is now by instantiating the object of class cl1. when i do that i get the execution will be broken directly.
Now may someone has any suggestion please to tell me how can i implement this object according to the above case correctly.