I am new in python and please excuse me if my question is a basic question or is not clear. I have a class in python and I want to set some attributes for my objects whenever I generate my objects from this class. I know, I must use __init__ method f
I mean to ask if it follows some specific algorithm and actually are not junk. In other words, how exactly the "garbage" values be present? Considering not invoking UB, if a garbage value is read, what is the source of that value?The standard do
I have a code and it can't read Bonus as a variable. Here is my code: #include <iostream> #include <string> using namespace std; int main () { char Bonus,Salary,TotalSalary; int num1, num2; cout <<"Enter the hours of work for week&q
In C++14: For any integral or enumeration type T and for any expression expr: Is there ever a difference between: struct S { T t { expr }; }; and struct S { T t = { expr }; }; Update: I got to [dcl.init.list]p3b5 which says: If the initializer list h
I've got strange problem with my constructor. I wrote class "Training" which represents some measured parameters. 5 out of 8 members are initialized directly, whereas rest need to perform simple calculations before value will be assigned to them
Is there an easy way to initialise an array using a function based on the indexes of each cell within the array? For example if I wanted to create an array with values equal to i+j+k such that (for example): > A[1,2,3] 6 > A[4,8,9] 21 I'd like somet
class Comp { //... }; class MyClass { private: vector<Comp*>vec; //... }; I need to initialize a vector of class type pointers to objects. how can I initialize it?You can set an initial size (e.g. 10, as shown below), filled with all NULL values wit
Looking into languages such as Java & C# use of uninitialized local variable is compile time error. Then why C & C++ allows uninitialized local variables? What is the reason that these languages allows this? I think many of the bad problems can't
I got an assignment for wich i have to write an program that will take the letters in the first parameter string, and find them in the second parameter string like so: ./a.out "lolabab" "ablcocllcab" the program needs to print "lo
Is it possible to initialise an array of uint8_t with a struct? What I want to achieve is something similar to: #define BIGGER_THAN_STRUCT 1024 struct Device { uint32_t address; uint32_t id; }; const uint8_t bytes[BIGGER_THAN_STRUCT] = (struct Device
I get these errors when i run this code I get these warnings that I really do not understand. When i change the == to a = i still get an error. : Use of uninitialized value in numeric eq (==) at ./pennies_again line 53, <$ogen_fh> line 2336 Use of u
I have some code where I have an int that starts off uninitialised, and is set later in the code (post user action). If the values haven't been initialised, then I use default values for display. I check if the values are 0 to tell if they've been in
I have gradually accumulated some open questions about the language's initialization syntax. Searching for answers can sometimes be relatively difficult when one does not know what to search for or is not aware of the correct terminology. Are my assu
This question already has an answer here: scanf fails why? 4 answers So I was wondering what happens if the user enters characters in integer variables for example: main() { int number; printf("Print a number:"); scanf(" %d", &numb
Is there an easy way (other than iterating through each element) to initialize n elements of @fields if it is not defined or empty ? my @fields = '-' x n; $string = 'a|b||c'; @fields = split(/\|/,$string); To create an array of n elements, you should
In Objective C, a custom init method must call the superclass's designated initializer. Consider the following custom init method for a sublcass of NSView: - (void)initWithFrame:(CGRect)aFrame andName:(NSString *)aName { if(self = [super initWithFram
Is the following definition bad style or plain wrong? That is, is it wrong to throw after having intialized a value that is considered incorrect? myClass::myClass(int arg) : value(arg) { if (value < 0) throw (myException("Negative value not allowe
Given this struct: struct PipeShm { int init; int flag; sem_t *mutex; char * ptr1; char * ptr2; int status1; int status2; int semaphoreFlag; }; That works fine: static struct PipeShm myPipe = { .init = 0 , .flag = FALSE , .mutex = NULL , .ptr1 = NULL
I have a C++ class with vector<float> members which are initialized in the constructor to a size determined by one of the constructor's arguments. summingBuffer = vector<float>(requiredSize); How do I check whether the vector constructor has s
I'm trying to write a little matrix program. Using doublke pointers doesnt work so I figure the easiest way is to have a struct that has the #rows and #columns and a 1d array as the matrix. But there is some error in the initiation of the matrix as i
I have written the following sample code : class MyClass { static int a; public: MyClass ( int i ) : a ( i ) { cout << " \n ctor called. a is : "<< a << " \n"; } }; int MyClass::a = 1; int main( ) { MyClass my(2); } I
Consider following code: // hacky, since "123" is 4 chars long (including terminating 0) char symbols[3] = "123"; // clean, but lot of typing char symbols[3] = {'1', '2', '3'}; so, the twist is actually described in comment to the code
I want to intialise a QHash as a global variable. Because it's global I can't write something like QHash<QString, int> MY_HASH; MY_HASH["one"] = 1; MY_HASH["two"] = 2; But I'm not sure how I would assign values to MY_HASH in its
Given the following code: class temp { public: string str; int num; }; int main() { temp temp1; temp temp2 = temp(); cout << temp1.str << endl; //Print "" cout << temp2.str << endl; //Print "" cout << temp
Hi what is the grrovy way of doing this kind of initialization? for(i=0; i<10; i++) for(j=0; j<20; j++) for(k=0; k<20; k++) m[i][j][k]='a' This could do: (0..9).each { i -> (0..19).each { j -> (0..19).each { k -> m[i][j][k] = 'a' } } }
This example is in C# but I expect could apply to others just as easily. I recently found that the following seems to work just fine: int i = Int32.TryParse(SomeString, out i) ? i : -1; Somehow it seems as though the variable i shouldn't technically
What is the proper way to initialize a null variable in .NET? I've been told by one of my colleagues that hard defining of a variable to null is a slowdown. int var1; // good practice string s1; // good practice int var2 = 0; // bad practice string s
So I'm declaring and initializing an int array: static final int UN = 0; int[] arr = new int[size]; for (int i = 0; i < size; i++) { arr[i] = UN; } Say I do this instead... int[] arr = new int[5]; System.out.println(arr[0]); ... 0 will print to stand
I'm new to C++ and I'm trying to figure out this problem I'm having with my constructor for one of my classes. What happens is... all my variables are initialized properly except two (health and type). #pragma once #include <irrlicht.h> #include <
I have just found out that the following is not valid. //Header File class test { const static char array[] = { '1', '2', '3' }; }; Where is the best place to initialize this?The best place would be in a source file // Header file class test { const