temporary

Getting Input from a Function - c++ [duplicate]

心不动则不痛 提交于 2021-02-05 09:42:52
问题 This question already has answers here : When I change a parameter inside a function, does it change for the caller, too? (4 answers) Closed 5 years ago . I've been having a problem in c++ where I call a function which assigns some values to things, but those assignments are lost after the function has been completed. Here is my code: #include <iostream> #include <string> using namespace std; void Input(string a, string b){ cout << "Input a: \n"; cin >> a; cout << endl; cout << "Input b: \n";

Getting Input from a Function - c++ [duplicate]

蓝咒 提交于 2021-02-05 09:42:38
问题 This question already has answers here : When I change a parameter inside a function, does it change for the caller, too? (4 answers) Closed 5 years ago . I've been having a problem in c++ where I call a function which assigns some values to things, but those assignments are lost after the function has been completed. Here is my code: #include <iostream> #include <string> using namespace std; void Input(string a, string b){ cout << "Input a: \n"; cin >> a; cout << endl; cout << "Input b: \n";

Is it safe to make a const reference member to a temporary variable?

此生再无相见时 提交于 2021-01-18 19:14:52
问题 I've tried to code like this several times: struct Foo { double const& f; Foo(double const& fx) : f(fx) { printf("%f %f\n", fx, this->f); // 125 125 } double GetF() const { return f; } }; int main() { Foo p(123.0 + 2.0); printf("%f\n", p.GetF()); // 0 return 0; } But it doesn't crash at all. I've also used valgrind to test the program but no error or warning occured. So, I assume that the compiler automatically generated a code directing the reference to another hidden variable. But I'm

Is it safe to make a const reference member to a temporary variable?

人走茶凉 提交于 2021-01-18 19:14:22
问题 I've tried to code like this several times: struct Foo { double const& f; Foo(double const& fx) : f(fx) { printf("%f %f\n", fx, this->f); // 125 125 } double GetF() const { return f; } }; int main() { Foo p(123.0 + 2.0); printf("%f\n", p.GetF()); // 0 return 0; } But it doesn't crash at all. I've also used valgrind to test the program but no error or warning occured. So, I assume that the compiler automatically generated a code directing the reference to another hidden variable. But I'm

How to pass a temporary array to a function in standard C++17

*爱你&永不变心* 提交于 2020-06-18 01:27:29
问题 I have a function of the following signature: void foo(int argc, char const * const argv[]); I would like to call it in a concise way, similar, but not necessary identical as below: foo(3, {"one", "two", "three"}); I know that C supports compound literals just for this purpose (reference). I also know how to solve the problem using templates (reference). However, my problem is slightly different. The function signature is fixed - it normally takes arguments passed to main and the size of the

How to control SQLite in memory DB consumption using C# vb.net

你。 提交于 2020-01-23 18:58:06
问题 I have 100 GB data. I want to load it in-memory using SQLite in VB.Net. I have 32 GB RAM. I want SQLite to take 24 GB RAM and other 8 GB will remain free for other OS tasks. When it hits the 24 GB RAM limit It should start flushing data to some disk file automatically. First: I used in-memory DB. Dim cn As SQLiteConnection = New SQLiteConnection("Data Source=:memory:") But it consumes 31.8 GB RAM, and then OS (Windows 7) jump in and takes the control and start using virtual memory (which

In S s = S() is it guaranteed that no temporary will be created?

橙三吉。 提交于 2020-01-14 07:19:44
问题 In the following code, are pS and s.pS guaranteed to be equal in the final line? In other words, in the statement S s = S(); , can I be sure that a temporary S will not be constructed? #include <iostream> using namespace std; struct S { S() { pS = this; } S* pS; }; int main() { S s = S(); S* pS = &s; cout << pS << " " << s.pS << endl; } In every compiler I've tested this in pS == s.pS , but I'm not sufficiently familiar with the standard to be able to satisfy myself that this is guaranteed.

constant references with typedef and templates in c++

时光怂恿深爱的人放手 提交于 2020-01-08 17:41:10
问题 I heard the temporary objects can only be assigned to constant references. But this code gives error #include <iostream.h> template<class t> t const& check(){ return t(); //return a temporary object } int main(int argc, char** argv){ const int &resCheck = check<int>(); /* fine */ typedef int& ref; const ref error = check<int>(); / *error */ return 0; } The error that is get is invalid initialization of reference of type 'int&' from expression of type 'const int' 回答1: This: typedef int& ref;

Create temporary file in C, MS Windows system

不问归期 提交于 2020-01-03 10:44:12
问题 Basically, i have a program that is given a 4 meg compressed file, it has to decode this file into uncompressed ~ 100 meg, then compress it back into ~4 meg file. I need to store this intermediate 100 meg file somewhere on the drive (dont want to keep it in memory). Program is written in C and will be executed on MS Windows 7. At the moment of uncompressing, no guaranteed folder (with write access) is given to the program (folder with source file might be read only and folder with target file

Does binding temporary to a reference require a copy constructor in C++?

寵の児 提交于 2020-01-03 08:38:29
问题 Consider the following code: class A { A(const A&); public: A() {} }; int main() { const A &a = A(); } This code compiles fine with GCC 4.7.2, but fails to compile with Visual C++ 2010 with the following error: test.cc(8) : error C2248: 'A::A' : cannot access private member declared in class 'A' test.cc(2) : see declaration of 'A::A' test.cc(1) : see declaration of 'A' So is it necessary to have a copy constructor accessible when binding a temporary to a reference? This is somewhat related to