c++

C++ Native Way to Pack and Unpack String

Following my earlier question. Is there a way to write a string in a compressed/bit version using C++ native idiom. I am thinking something like Perl's native pack and unpack. ...

How can I count the number of callstack frames?

For a C++ debug application I want to be able to count the number of callstack frames easily. Is there an OS function to do this? I need this for Windows and Posix, i.e. cross platform. Solutions to either or both platforms would be great. I can walk the stack to find all of the frames but I wondered if there was an easy call to do thi...

Create WCF service for unmanaged C++ clients

I need to get unmanaged Windows C++ clients to talk to a WCF service. C++ clients could be running on Win2000 and later. I have a control over both WCF service and which C++ API is being used. Since it's for a proprietary application, it is preferable to use Microsoft stuff where possible, definitely not GNU licensed APIs. Those of you w...

Why is my return type meaningless?

I am trying to use a return type of const MyClass * const. However, I get a warning: Warning: #815-D: type qualifier on return type is meaningless. Is this not a valid type? I want a pointer than cannot be changed, and I want the thing it points to to not be changed either. ...

Is it possible to provide exceptions in C++ virtual(pure) class member?

If so how? I know how to provide exception specifications for members such as class SOMEClass { public: void method(void) throw (SOMEException); virtual void pure_method(void) = 0; }; So that the method throws only SOMEException. If I want to ensure that sub-classes of SOMEClass throw SOMEException for pure_method, is it p...

c++ conditional macro evaluation

I have a symbol defined globally that needs to be conditionally undefined for a given subset of my source files. All of the files that require special treatment are already wrapped in pre- and post-inclusions: pre.h: #undefine mysymbol // [1] post.h: #define mysymbol MY_SYMBOL_DEFINITION // [2] My problem is that the pre.h and pos...

What is the origin of the throw/catch exception naming?

Was the creator of this construct a baseball fan? ...

What Genetic Algorithm/Programming library do you use?

What GA/GP lib do you use and why? ...

C++ Undefined Reference (Problem with Include)

Hello! I cannot get this simple piece of code to compile without including the TestClass.cpp file explicitly in my main.cpp file. What am I doing wrong? Thanks in advance! Here is the code: TestClass.h #ifndef TESTCLASS_H_ #define TESTCLASS_H_ class TestClass { public: static int foo(); }; #endif TestClass.cpp #includ...

StyleCop for C++

I would like to ask do You know any programs similar to StyleCop but for C++? ...

How Do You Call an MSSQL System Function From ADO/C++?

...specifically, the fn_listextendedproperty system function in MSSQL 2005. I have added an Extended Property to my database object, named 'schemaVersion'. In my MSVC application, using ADO, I need to determine if that Extended Property exists and, if it does, return the string value out of it. Here is the T-SQL code that does what I ...

C++ const std::map reference fails to compile

Is there a reason why passing a reference to a STL map as const causes the [] operator to break? I get this compiler error (gcc 4.2) when I use const: error: no match for ‘operator[]’ in ‘map[name]’ Here's the function prototype: void func(const char ch, std::string &str, const std::map<std::string, std::string> &map); And, I ...

Are C++ int operations atomic on the mips architecture

I wonder if I could read or write shared int value without locking on mips cpu (especially Amazon or Danube). What I mean is if such a read or write are atomic (other thread can't interrupt them). To be clear - I don't want to prevent the race between threads, but I care if int value itself is not corrupted. Assuming that the compiler a...

How can I build a std::vector<std::string> and then sort them?

I have a bunch of strings that I need to sort. I think a std::vector would be the easiest way to do this. However, I've never used vectors before and so would like some help. I just need to sort them alphanumerically, nothing special. Indeed, the string::compare function would work. After that, how can I iterate through them to verify ...

What to put in precompiled header? (MSVC)

What are the best candidates for a precompiled header file? Can I put STL and Boost headers there, even though they have templates? And will that reduce compile times? Also, what are the best IDE settings to reduce compile times? ...

How can adding code to a loop make it faster?

I have a simple function with an inner loop - it scales the input value, looks up an output value in a lookup table, and copies it to the destination. (ftol_ambient is a trick I copied from the web for fast conversion of float to int). for (i = 0; i < iCount; ++i) { iScaled = ftol_ambient(*pSource * PRECISION3); if (iScaled <=...

How do I force my app to come to the front and take focus?

I'm working on an application that happens to be the bootstrap for an installer that I'm also working on. The application makes a few MSI calls to get information that I need for putting together the wizard that is my application's main window, which causes a progress window to open while the info is being gathered and then go away once ...

IS C++ converted into MSIL?

I have been a long time C# and .Net developer, and have been playing with the idea of learning c++. One of the primary reasons I have been thinking about this, is how much faster C++ can be over apps using the .Net framework. But am I right in assuming that if I write a C++ app in Visual Studio, and/or reference .Net libraries in a C++...

Best practices for defining your own exception classes?

I have some special exception cases that I want to throw and catch, so I want to define my own exception classes. What are the best practices for that? Should I inherit from std::exception or std::runtime_error? ...

Variable Sized Struct C++

Is this the best way to make a variable sized struct in C++? I don't want to use vector because the length doesn't change after initialization. struct Packet { unsigned int bytelength; unsigned int data[]; }; Packet* CreatePacket(unsigned int length) { Packet *output = (Packet*) malloc((length+1)*sizeof(unsigned int)); ...