using the __init__ method with and without parameters

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

How are trash values ​​for variables generated in C?

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

Can not read Bonus as a variable

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

class pointers initialization vector

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

Why does C allow uninitialized local variables?

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

Need a string initialization tip

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

Initialize table C with struct

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

Perl uninitialized value in numeric code

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

Checking an uninitialized int when a real value could be 0?

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

How to initialize a pointer to a C structure?

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

C matrix, allocation does not zero all the elements?

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

Initialize a non-const static data member of a class

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

Char array initialization dilemma

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

Initialize Global & lt; Key, Value & gt; Chop

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

Default C ++ constructor

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

What's the great way to do this initialization?

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' } } }

Initializing null variables in .NET

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

What is the default initialization of an array in Java?

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

C ++ constructor problem, values ​​not being defined

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 <

Initializing the static static matrix in the header file

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