[Solved] Global variables, member variables and instance variables in Python [closed]

You have asked a lot of questions under one! I will try to answer each of those 🙂 Variables – global vs local global variables are those ones whose scope is global, i.e. available in entire program. local variables by contrast are those ones which resides in one particular scope, a function, inside a loop, … Read more

[Solved] Cannot run Java Runtime.exec() on Opensuse

So far so good! I found the answer recently by myself, still don’t have a reason why it works this way, but I suppose it’s all about internal difference of handling new processes in VM’s on different platforms. I had to edit the code this way, and now it works: String[] runcmd = {“java”,”-jar”,”/home/user/jar.jar”}; Runtime.getRuntime().exec(runcmd); … Read more

[Solved] Making a new function by fixing one of the input parameters [closed]

You probably want lambda or std::function, or std::bind auto l_add_100 = [](double x) { return add_two_numbers(x, 100); }; std::function<double(double)> f_add_100 = [](double x) { return add_two_numbers(x, 100); } auto b_add_100 = std::bind(add_two_numbers, std::place_holder::_1, 100); or with non hard coded number double y = //… auto l_add_y = [y](double x) { return add_two_numbers(x, y); } std::function<double(double)> … Read more

[Solved] How to convert mysql function into sqlsrv? [closed]

You are missing the connection parameter to sqlsrv_query. While you’re at it, you might as well use bind variables instead of string substitution to help guard against SQL-Injection attacks. $serverName = “serverName\instancename”; $connectionInfo = array( “Database”=>”dbName”, “UID”=>”username”, “PWD”=>”password” ); $conn = sqlsrv_connect( $serverName, $connectionInfo); $params = array($username, $password); $stmt = sqlsrv_query ($conn, ‘select * from … Read more

[Solved] Upload photos with NSURLSession in background

From the comments above, it seems like you’ll be uploading several photos at a time and for that a “fromData” approach does not seem like a good idea. Firstly, high resolution photos have several megabytes in size. If your loading a 5mb photo into memory, using NSData, you’re probably fine. But loading 10 photos would … Read more

[Solved] A_Class cannot be cast to B_Class?

Your class hierarchy is: class Home_Page extends AppCompatActivity class MainActivity extends AppCompatActivity This is similar to the following: class Dog extends Animal class Cat extends Animal You can cast a Dog to an Animal, but you can’t cast a Dog to a Cat. In the same way, you can’t cast a Home_Page to a MainActivity. … Read more

[Solved] Weird issue in C [closed]

This is taken from your code: char *compar; if(i==0){ sprintf(&compar,”%c%c%c%c”,code[0],code[1],code[2],code[3]); } The problem here is that you declare compar as a pointer to char, but it is uninitialized. So, it has an undefined value. When you fill it with sprintf, you just write somewhere in the memory, and apparently, you write over the variable nombre_instruction. … Read more

[Solved] What does this code snippet do exactly?

The following line: vector<int> clusters(k,0); Defines a random-access collection of k total integers each with an initial value of 0. clusters[id] accesses the integer value stored at index id in the vector. clusters[id]++ increments the integer value stored at index id. This works because operator [] on a vector returns a reference to the indexed … Read more

[Solved] What is wrong with this C++ code?

first of all your bool prime; is not initialized. Second it should be initialized inside do while() loop and it is better to move that variable declaration there: bool prime = false; // move it here and initialize for (i = 2; i < n; ++i) { if (n % i == 0) prime = … Read more