c++

Sharing static members between template instantiations? (impossible?)

I am doing something that is probably silly, but it would be nice if it worked. I am attempting to specialize types in a way that I need my own lookup structure that is essentially global (but ideally encapsulated as a class variable), but I want the objects to be type safe, so they are parameterized. Consequently, I have, essentially ...

PCap performance

Which c-sharp wrapper of Pcap is fastest? How fast is PCap compared to using sockets? ...

C++ MySQL and multithreading - 1 DB connection per user?

Hi, Is in multithreaded application suitable to have 1 connection per 1 connected client? To me it seems ineffective but if there is not connection pooling, how it could be done when one wants to let each connection communicate with DB? Thanks ...

How can I streamline complex nested protobuf validation in C++?

I'm using Google protocol buffers in a messaging application. The protos are often nested several levels deep, and we have taken Google's advice and made them all optional. The protos can describe many different types of overlapping messages - i.e. a message of Type == X should contain the member my_X, Type == Y should contain my_Y. Fu...

What to do with template typenames for optional arguments?

First of all, the code: template<typename Func, typename Func2> void ForEachField(Func normalHandler, Func2 arrayHandler = NULL, bool skipUnknowns = true) { for(int i = 0; i < mFields.size(); ++i) { Field *f = mFields[i]; if(skipUnknowns && f->IsUnknown()) continue; if(f->GetCount() == 1 || ...

Reverse doubly-link list in C++

I've been trying to figure out how to reverse the order of a doubly-linked list, but for some reason, in my function void reverse() runs while loop once and then crashes for some reason. To answer some questions ahead, I'm self-teaching myself with my brothers help. This isn't all of the code, but I have a display() function which prin...

new types may not define a return type - C++

I am confused I think on C++ class structure. I have a .h called FxMathFunctions.h and a .cpp called FxMathFunctions.cpp the .h starts like: class FxMathFunctions { public: FxMathFunctions(); ~FxMathFunctions(); and in the .cpp I have: #include "FxBasicTypes.h" #include "FxMathFunctions.h" FxMathFunctions::F...

D3D10 HLSL: How do I bind a texture to a global Texture2D via reflection?

Ok so assuming I have, somewhere in my shader, a statement as follows (Note I am enabling legacy support to share shaders between DX9 and DX10): Texture2D DiffuseMap; I can compile up the shader with no problems but I'm at a slight loss as to how I bind a ShaderResourceView to "DiffuseMap". When I "Reflect" the shader I rather assu...

how to call excute comand line in C++

For example, I have a script ./helloworld.sh I would like to call it in C++, how to do that? which lib can be used? ...

File not found error with LoadImage() (Windows)

EDIT: I've added a few more lines of the program to the code snippet below. I have the following line of code in a program BITMAP BMP; HBITMAP hBMP; hBMP = (HBITMAP)LoadImage(GetModuleHandle(NULL), "Test.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE); if (!hBMP) return 1; GetObject(hBMP, sizeof(BMP), &BMP); and wh...

C++ catching dangling reference

hello Suppose the following piece of code struct S { S(int & value): value_(value) {} int & value_; }; S function() { int value = 0; return S(value); // implicitly returning reference to local value } compiler does not produce warning (-Wall), this error can be hard to catch. What tools are out there to help catch...

Nested NameSpaces in C++

I am confused what to do when having nested namespaces and declaration of objects. I am porting some code that links against a static library that has a few name spaces. Example of what I am talking about: namespace ABC { namespace XYZ { //STUFF } } In code what so I do to declare an object that is in namespace XYZ...

Accessing an enum in a namespace

In a header I have a setup like this namespace NS { typedef enum { GOOD, BAD, UGLY }enum_thing; class Thing { void thing(enum_thing elem); } } and of course another cpp file that goes along with that header. Then I have a thread cpp file that contains main(). In this cpp file I use that enum to pass to the method t...

Create a function pointer which takes a function pointer as an argument.

How to create a function pointer which takes a function pointer as an argument (c++)??? i have this code #include <iostream> using namespace std; int kvadrat (int a) { return a*a; } int kub (int a) { return a*a*a; } void centralna (int a, int (*pokfunk) (int)) { int rezultat=(*pokfunk) (a); cout<<rezultat<<endl; } ...

C++ timeout on getline

I need all of my threads to check periodically that they should still be running, so that they can self-terminate when the program ends. For all but one of them, this is just a matter of checking a state variable, but the last one is a user-interaction thread, and its loop will wait indefinitely on user input, only checking the state var...

How can I set up a CBT hook on a Win32 console window?

Hello, I've been trying to set up a CBT hook for my C++ Console application with the following code: ...includes... typedef struct _HOOKDATA { int type; HOOKPROC hookproc; HHOOK hhook; }_HOOKDATA; _HOOKDATA hookdata; //CBT LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam) { //do not proccess m...

Define BIT0, BIT1, BIT2, etc Without #define

Is it possible in C++ to define BIT0, BIT1, BIT2 in another way in C++ without using #define? #define BIT0 0x00000001 #define BIT1 0x00000002 #define BIT2 0x00000004 I then take the same thing and make states out of those bits: #define MOTOR_UP BIT0 #define MOTOR_DOWN BIT1 Note: I am using 32 bits only, not 64 bits. I am also usi...

Fastest way of doing transformations (Move, Rotate, Scale)

I was looking at this vector drawing application called Creative Docs .Net . I noticed that I can have hundreds of shapes and moving, rotating and scaling do not lag at all. Given that all verticies must be modified, how do applications generally do these transformations as quickly as possible? Thanks ...

Determining wether a class has a certain member?

Possible Duplicate: Possible for C++ template to check for a functions existence? I am trying to determine wether a type has a certain member. This is what i tried: template <typename T,typename U=void> class HasX { public: static const bool Result=false; }; template <typename T> class HasX<T,typename enable_if_c<(sizeof...

Synchronizing access to a return value

Consider the following C++ member function: size_t size() const { boost::lock_guard<boost::mutex> lock(m_mutex); return m_size; } The intent here is not to synchronize access to the private member variable m_size, but just to make sure that the caller receives a valid value for m_size. The goal is to prevent the function f...