Firstly thank you for your help. However my program implements a scientific method and is contained within a single source file which I believe negates some of the disadvantages of global const variables that you have outlined.
The method is an iterative process calling several functions. Many of these functions require knowledge of some values governing a physical system. As I outlined originally these values were declared in main...
User Profile
Collapse
-
global variables/passing
Currently writing a program which uses several constant values (all numbers) in main() and also in various functions. Currently I initialise and assign these values in main() and pass the required ones to each function.
As these values do not get changed would it be better/quicker to have these numbers defined as const global variables?
Thanks for the help! -
Thank you that works! can you explain why? (I am trying to understand my code as well as write it!) Also do you know why your dynamic suggestion didnt seem to work for me?...Leave a comment:
-
changed to
Still the same error message.Code:template<class T> VEC<T>::~VEC() { if(v != NULL) delete[] (v); }
I also tried
...Code:int main(void) { VEC<double> *a; a=new VEC<double>(10); int n; for (n=0;n<10;n++) { a[n]=double(n); printf("a[%d]=%e\n",n,a[n]); } deleteLeave a comment:
-
Using this the program compiles and runs outputting the vector but then aborts with the following error.
*** glibc detected *** double free or corruption (top): 0x0804a008 ***...Leave a comment:
-
Using a destructor on a Vector class
I wish to use a C++ vector class, which I have taken from the book numerical recipes. However due to the nature of the calculations I wish to perform I need to be able to delete the vectors. I thought that the line ~VEC<double>(a) ; would do this however when trying to compile using g++ I get the error
"no match for ‘operator~’ in ‘~VEC<double>(( (const VEC<double>&)(( const VEC<double>*)(& a))))"...
No activity results to display
Show More
Leave a comment: