c++

Retrieving a c++ class name programatically

I was wondering if it is possible in C++ to retrieve the name of a class in string form without having to hardcode it into a variable or a getter. I'm aware that none of that information is actually used at runtime, therefor it is unavailable, but are there any macros that can be made to create this functionality? Thanks. Edit: May be h...

64bit shift problem.

Why this code does not write 0 as a last element but 18446744073709551615? (compiled with g++) #include <iostream> using namespace std; int main(){ unsigned long long x = (unsigned long long) (-1); for(int i=0; i <= 64; i++) cout << i << " " << (x >> i) << endl; cout << (x >> 64) << endl; return 0; } ...

Visual studio release build

Hello, I'm trying to generate a release build for a C++ application that I've written. The application runs fine (debug & release) when you run it from within VS2008; but when you run the executable it crashes nearly every single time. Now, is there a hack so I can run this application as a standalone application without having to run...

Regression testing in C++

I can't use unit tests for some parts of code so I'm falling back to regression tests. I would like to check whether my program behaves in the same way after some modifications. And by behaviour I mean mostly a state of data structures. So far I was serializing them into human readable text format and dumped to some files in the first r...

Choice of language for portable library

I want to write a library which will be dynamically linked from other programs running on modern operating systems like Windows, Linux and OS/X (i.e. it will be deployed as a .dll or .so module). What is the most appropriate language in that case? Should I stick with plain C? Or is C++ also ok? ...

C++: Will an 'empty' destructor do the same thing as the generated destructor?

Suppose we have a (toy) C++ class such as the following: class Foo { public: Foo(); private: int t; }; Since no destructor is defined, a C++ compiler should create one automatically for class Foo. If the destructor does not need to clean up any dynamically allocated memory (that is, we could reasonably rely on...

extern C can not be used at class level?

Hello everyone, Just want to confirm in Windows environment, VSTS 2008 + C++ project, we could only apply extern C to function level, not be able to apply to class level (so that all member functions from the class use C language name mangling)? I have tried several ways, but always compile error. thanks in advance, George ...

Can I dynamically determine all solutions, projects and configurations on a build/trigger event and call them all with MSBuild (from command line/script)?

We're still a little early in setting up our build automation and just using a bat file for now for Win32 C++ solutions. We have about 4 solutions and each has a couple vcproj files. Each time a new solution or configuration is added I have to update the bat file to reflect the new solution or configuration to call with MSBuild. I...

Obfuscating C/C++ Code

Hi there What tools are available to obfuscate C/C++ code. I would prefer an open source solution. Thanks Update: Regarding the "use the compiler" responses I am aware of that but I have a client that wants to obfuscate their C/C++ code none the less I personally don't understand why, I have just been made responsible to implement a s...

Thread implemented as a Singleton

Hi all, I have a commercial application made with C,C++/Qt on Linux platform. The app collects data from different sensors and displays them on GUI. Each of the protocol for interfacing with sensors is implemented using singleton pattern and threads from Qt QThreads class. All the protocols except one work fine. Each protocol's run func...

When to use a void pointer?

I understand the use of void pointer for malloc implementation. void* malloc ( size_t size ); Can anyone suggest other reasons or provide some scenarios where it is useful in practice. Thanks ...

Getting a class/struct object from the member pointer

I have C++ structure as struct myStruct { int a; int b; int c; }; myStruct b; int *ptr = &b.c; How can I get myStruct object back from ptr? (I know I can do this using pointer arithmatic like container_Of() in C. Basically something like reinterpret_cast<myStruct*>(reinterpret_cast<char *>(ptr) - offsetof(myStruct, c)...

Modifying a C string: access violation

Possible Duplicates: Why does simple C code receive segmentation fault? Modifying C string constants? Why does this code generate an access violation? int main() { char* myString = "5"; *myString = 'e'; // Crash return 0; } ...

Any way to detect whether the pointer points to array?

Hi, everyone! Is there any way to detect, whether the pointer points to array in C++? My problem is that I want to implement a class, that becomes the owner of the array. My class is initialized with the pointer and I would like to know, whether the pointer is really an array pointer. Here is the simplified code: class ArrayOwner { pub...

When implementing operator[] how should I include bounds checking?

First of all I apologize for the long lead up to such a simplistic question. I am implementing a class which serves as a very long 1 dimensional index on a space filling curve or the n-tuple representing the Cartesian coordinate that index corresponds to. class curvePoint { public: friend class curveCalculate; //Construction a...

Namespaces in C++ header files

I like the concept of C++ namespaces, because they help to keep the source code concise while avoiding name conflicts. In .cpp files this works very well, using the "using namespace" declaration. However, in header files this cannot be used, as it "breaks open" the namespace, meaning that the "using namespace" not only applies within the...

What is difference between my atoi() calls?

I have a big number stored in a string and try to extract a single digit. But what are the differences between those calls? #include <iostream> #include <string> int main(){ std::string bigNumber = "93485720394857230"; char tmp = bigNumber.at(5); int digit = atoi(&tmp); int digit2 = atoi(&bigNumber.at(5)) int digit3...

How can I obtain a LaVectorDouble object which is a submatrixview of a LaGenMatDouble?

We are using Lapack++ for our matrix calculations. One of the features is the use of submatrixviews; objects that refer to the same spot in memory. Example: LaGenMatDouble W = LaGenMatDouble::rand(3,4); LaGenMatDouble A = W(LaIndex(0,2), LaIndex(1,3)); LaGenMatDouble b = W(LaIndex(0,2), LaIndex(0,0)); A and b are now submatrice...

Creating arrays on the heap and addressing them with pointers

Hi, I'm having trouble understanding the following bit of code that I was hoping would create an array on the heap and fill it with the characters 9 down to 0 (I know I could just index the array like a normal stack array with [] notation to do this but I'm doing it this way to try to understand pointers in more depth): int *ptrHeapArra...

How to pass two parameters when using std::mem_fun?

Lets say I have hierarchy like this (This is just a test program. Please do not point anything related to memory leaks, destructor is not virtual etc): class I { public: virtual void fun(int n, int n1) = 0; }; class A : public I { public: void fun(int n, int n1) { std::cout<<"A::fun():" <<n<<" and n1:" <<n1<<"\n"; ...