c++

What benefit is there of allowing a variable to be left uninitialized?

In many languages you're allowed to declare a variable and use it before initializing it. For example, in C++, you can write a snippet such as: int x; cout << x; This would of course return unpredictable (well, unless you knew how your program was mapping out memory) results, but my question is, why is this behavior allowed by compil...

evaluate whether a number is integer power of 4

The following function is claimed to evaluate whether a number is integer power of 4. I do not quite understand how it works? bool fn(unsigned int x) { if ( x == 0 ) return false; if ( x & (x - 1) ) return false; return x & 0x55555555; } ...

how to create an utf8 string in Google V8 engine

Hello Im using v8 engine embedded in C++ program and I met a string problem. Well of course v8 engine fully support utf8 string, but i just dont know how. char path[ 1024 ]; GetCurrentDirectory( 1024, (LPWSTR)path ); script->Path = String::New(path); However, the result is the only character "D", for String::New only accepts char*...

C++ vectors of classes with constructors.

//Using g++ and ubuntu. #include <vector> using namespace std; Define a class: class foo(){ (...) foo(int arg1, double arg2); } Constructor: foo::foo(int arg1, double arg2){ (...) //arrays whose length depend upon arg1 and arg2 } I would like to do something like this: vector<foo> bar(10); //error: no matching function for cal...

Question about namespace.

Possible Duplicate: Why are unnamed namespaces used and what are their benefits? namespace { // EINTR sucks. int close_no_eintr(int fd) { int result; do { result = close(fd); } while (result < 0 && errno == EINTR); return result; } In the code above, why there is not a name after namespace in the first line? ...

check NaN number

Hi, is it possible to check if a number is NaN or not? UPDATE: my mistake. fixed the Question. ...

Why does C++ support memberwise assignment of arrays within structs, but not generally?

I understand that memberwise assignment of arrays is not supported, such that the following will not work: int num1[3] = {1,2,3}; int num2[3]; num2 = num1; // "error: invalid array assignment" I just accepted this as fact, figuring that the aim of the language is to provide an open-ended framework, and let the user decide how to imple...

C++ coding standard for small group using modern IDEs

Hi, We are going to start a new project in our team which consists of less than 10 developers. We have access to modern IDEs such as VS2010. The project is extremely dynamic (users' needs change very quick) and cross platform. Therefore, I need a highly readable and very detailed C++ coding standard so new developers can easily change ...

Is it possible to recreate the C++ header files needed to use a given .dll/.so/.dylib?

Is it possible to recreate the C++ header files needed to use a given .dll/.so/.dylib? If it is, how would one go about doing that? ...

RegQueryValueEx and REG_BINARY

Hi all, I tried to read a REG_BINARY value of the Windows registry, but I don't know how... I'm really new to the c++ world and I hope that you'll be cool and help me with that problem. I found that code on this website, I know this is not doing the job, but just for let you know what I'm trying to do. #include <iostream> #include <win...

Are STL Map or HashMaps thread safe?

Can I use a map or hashmap in a multithreaded program without needing a lock? i.e. are they thread safe? I'm wanting to potentially add and delete from the map at the same time. There seems to be a lot of conflicting information out there. By the way, I'm using the STL library that comes with GCC under Ubuntu 10.04 EDIT: Just like th...

using a string variable declared in one class globally in entire project.

Hi, I have a string variable as: string name = "MyName"; in one cpp file. How can i use the same string variable in another class within the same project. ...

Use functional in Vector in C++

I have made big mistake. It is about vector. #include <iostream> #include <ostream> #include <string> #include <vector> #include <functional> #include <algorithm> using namespace std; int main() { vector<int,greater<int>>v; v.push_back(11); v.push_back(22); v.push_back(33)...

Solving random crashes

I am getting random crashes on my C++ application, it may not crash for a month, and then crash 10 times in a hour, and sometimes it may crash on launch, while sometimes it may crash after several hours of operation (or not crash at all). I use GCC on GNU/Linux and MingW on Windows, thus I can't use the Visual Studio JIT Debug... I hav...

Using boost memory pool in class

I tried to declare a memory pool in my class. But the compiler shows some basic error like missing ')' before ';' or syntax error : 'sizeof' It works well if I used the pool as local variable but I really want to make it live with the class. What's wrong about my usage? Here is the class, the MAX_OBJ is a const class CData { publi...

non-const actual param to a const formal param

The const modifier in C++ before star means that using this pointer the value pointed at cannot be changed, while the pointer itself can be made to point something else. In the below void justloadme(const int **ptr) { *ptr = new int[5]; } int main() { int *ptr = NULL; justloadme(&ptr); } justloadme function should not be...

Serialise and deserialise vector in binary

Hi all, I am having problems trying to serialise a vector (std::vector) into a binary format and then correctly deserialise it and be able to read the data. This is my first time using a binary format (I was using ASCII but that has become too hard to use now) so I am starting simple with just a vector of ints. Whenever I read the dat...

equivalent encryption/decryption functions on C++ linux and C# windows

hello. i have both a web gui written in C#, running on IIS server and C++ written engine, running on apache. i need my web gui to encrypt and the C++ engine to decrypt the data. what equivalent function can i use to achieve my purpose ? ...

SetupDiGetDeviceProperty

Dear friends.. Can anybody provide me the example of using SetupDiGetDeviceProperty () I have searched via google but i cant get it to work.. Thank you ...

vector of vector

for example we have following code pragment #include <iostream> #include <ostream> #include <vector> using namespace std; int main() { vector<vector<int>>v; return 0; } i have question as i see this form v.push_back(11) does not work what will be correct? ...