in a header file and the header file is included in several C files.
Questions:
At run time,
Is there just one copy of the const variable my_fl_dark_gray or are there multiple copies for the multiple C files?If a function uses the const variable, does the initialization statement "my_fl_dark_gray=fl_color_cube(...);" run every time the function is called or does it just run once and then when the function is called it just uses the value stored in memory?
Is there any way to cast a non-const variable to const one?
I want to read variable n from file and then use it to declare array "int arr[n]", but because n is non-const, the compiler doesn't allow me to do that.
I get an error when i try to compile this code. I tried to allocate memory in main function and that works. But why it doesn't work in function? I think that there is something wrong with function argument, but not sure.
Code:
#include <iostream> #include <fstream> using namespace std; struct Word
I am writing a program to calculate a rectangle's area.
Eg. Enter top left point: 1 1 (User input) Enter bottom right point: 2 -1 (User input) Top Left x = 1.000000 y: 1.000000 Bottom Right x = 2.000000 y: -1.000000 Area = 2.000000 (Program output)
It keeps on prompting me my variable r is being used without being initialized, when I think I already did so.
I've created a program meant for submission for my final project but when i ran it, it shows that the variable being used without being initialized for quite a few time. My program is below.
when i compile my code i get this error : "error : variable-sized object 'largeArray2' may not be initialized"
Code:
float give_coefficients_routh_table_and_fill_two_first_lines(int denominator_degree) { float largeArray2[20][20] = {0}; int l = 0; int c = 0; int e = denominator_degree ; for ( e = denominator_degree; e>=0; e--)
Under visual studio, this is a typical run time error,
Code: void func(int x){ x = 3; } int main() { int x; func(x); }
When x is passed to the function func, it is not initialized. But my question is that why it should be an error? On the other hand, if I change the definition of func a little bit like this,
Code: void func(int& x) { *x = 3; } int main() { int x; func(&x); }
Now in main, x is still not initialized, but this time there isn't a run time error like "the variable is being used without being initialized. Why?
I have a class that defines a window (a popup dialog of sorts), and I want the name of that window to be constant. The only problem is that the name of the popup needs to match the title of the parent window, and I get the name of the parent in the constructor. So how do I go about defining this member variable to be constant and initializing it with a value in the constructor?
I want to do something like this, but I know this isn't allowed:
/* class.h */ class foo { public: foo(*parentWindowPtr);
[Code] .....
I should mention that yes the name of the parent window is const char *, and I would like to keep it this way.
I'm having to do a little c++ (coming from java) and don't understand the syntax of the following declaration
Code: SensorBase* const sensor(mSensors[i]);
It looks like it's declaring a const pointer to a SensorBase object but I don't understand how that applies to sensor(mSensors[i]) which looks like a function??
This does not allow me to initialize _listRef as something like NULL when it is not applicable.Also, i must change all my constructors and its child class to include an initialization of _listRef!!
What is the alternative? Is pointer the nearest? which of the following should be used?
Code: const QList<QSharedPointer<Data>> * _listRef; or const QList<QSharedPointer<Data>> *const _listRef; or const QSharedPointer<QList<QSharedPointer<Data>>> _listRef; ????
Are there other ways of calling a const/non-const override? I want to defined some functions in terms of others, particularly accessors which might or might not require constness- in order to not copy & paste code. This is my current solution:
difference between const and static const, more effectively. I know the basic concept of const and static but I need clear explanation of declaring "const" and "static const"
I just finished coding a program that is based on polymorphism and inheritance but when I ran the program it crashed? I do not know what is the cause of the program crashing.
#include<iostream> #include<string> using namespace std; class Shape{ float density;
I want to be honest, this is FOR homework, but is NOT homework. I have created this example to work from in order to understand qsort further because the next assignment requires it's use.
Our teacher gave us this small piece of example code and I am trying to expand on it to serve my purpose. [C] Sorting - Pastebin.com
The code gives me no errors, but does not sort the array. Need to clarify the use of qsort in this instance.
I am imagining that the reason it's not sorting properly ( or at all ) is because of my comparison function. That is really just an assumption. Or perhaps I just don't understand the pointer array i'm using.
How do I copy from a dynamic array initialized in a class but with a different memory address. For example if my array is a dynamic array initialized in a class...
Code: const int CAPACITY=5; class Array{ public: Array();//constructor
[Code] .....
How would i copy this array to a another array but have a different memory address so when i deallocate array a my copy array also isn't deallocated.
Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { int i; int arr[3];
[Code] ....
Notice we didn't set a value for second index but it returns 0. Should I assume that when declaring an array with n values, those values will be initialized to 0 automatically or should I still initialize the array with all 0s doing something like this:
This code worked perfectly fine in Xcode earlier today, but when I got home on visual studio 2012 express it is having an error. It's saying that the local function definitions are illegal and has a red mark under the '{' only?