c++

Using GDB with external libs

I'm currently debugging a project that uses an external library (LibFirm). When i call library functions, I can't really see what's going on there with gdb (i.e. I can't inspect local variables and such). The library is open source and I compiled it myself, so I think it should be possible to let gdb look into it too. How? What I am cu...

When to use signals and slots and when not to

We're using Qt that offers signals and slots which I find really convenient. However, with great power comes great responsibility and I think it's very easy too misuse this feature. Are there any best-practices for signal-slot usage? I'm having a hard time to find some general guidelines in this manner. Some questions (I have clear opi...

Inheritance with CRTP

I have these 3 classes. class A { public: virtual void Func() = 0; }; template<class T> class B : public A { public: void Func() { cout << "In B" << endl; static_cast<T*>(this)->Func(); } }; class C : public B<C> { public: voi...

simulink link by tcpip with c++ application

Hello, I 'am triyng to build a link between my simulink model or just a m file and my c++ applicaton but i 'am having an issue. I don't really understand how matlab receive the data. and for simulink in which form should i send the data to the block ? I would like to send coordinates like xyz to matlab and with matlab scatter3 the stre...

Generate random numbers following a normal distribution in C/C++

Does anyone know how I could easily generate random numbers following a normal distribution in C/C++ ? http://www.mathworks.com/access/helpdesk/help/toolbox/stats/normrnd.html I don't want to use any of Boost. I know that Knuth talk about this at length but I don't have his books at hands right know. Thanks, ...

Adding default arguments to variadic macro

Hi, Is it possible to add default arguments before variable argument in variadic macro? e.g I have the version of macro something like #define MACRO(arg1, ...) func(arg1, ##__VA_ARGS__) I would like to add 2 more default arguments in the macro before variable arguments so that it should not affect previous version. Like: #define MAC...

How to access image Data from a RGB image (3channel image) in opencv

I am trying to take the imageData of image in this where w= width of image and h = height of image for (int i = x; i < x+h; i++) //height of frame pixels { for (int j = y; j < y+w; j++)//width of frame pixels { int pos = i * w * Channels + j; //channels is 3 as rgb // if any data exists if (data->imageD...

ReadFile, COM and NULL characters in c++

I have a problem with ReadFile function in a virtual serial port: char tmp[128]; int multiplo=0; DWORD err; COMSTAT stt; ClearCommError(hcom, &err, &stt); do{ if(ReadFile(hcom, tmp, stt.cbInQue, &err, NULL)){ tmp[err] = '\0'; memcpy(bfIn+multiplo, tmp, err); multiplo = multiplo + err; }else retur...

How to define NULL using #define

I want to redefine NULL in my program such as #define MYNULL ((void*)0) But this definition is not working in the following statement: char *ch = MYNULL; Error : can not convert from void* to char * What would be the best way to define NULL? ...

how to change the default exe icon in C/C++?

Hello friends,I want to change the default exe icon to someother icon in c/c++ do anybody know how to do that?Please help guys... ...

generating a 3d graphics c++

Hello, I have found an interesting application on the net and i am using it for my end year study project. http://www.cl.cam.ac.uk/~sjeh3/wii/ the video in the link explains my goal. But i am having issue using it. the example of rendering the trajectory on a 3d axis is using Corba (omniorb) and i believe open inventor. but there isn't ...

CMake compile C++ file in custom command.

Hello, I'm trying to precompile a header file in GCC with the following command: ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/all.hpp.gch COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} -o ${CMAKE_BINARY_DIR}/all.hpp.gch ${CMAKE_CURRENT_SOURCE_DIR}/all.hpp DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/all.hpp COMMENT "G...

Difference between InvalidateRect and RedrawWindow

When I want to redraw a window, is there any preferred function to call between InvalidateRect and RedrawWindow? For instance, are these two calls equal: (win would be a HWND) RedrawWindow(win, NULL, NULL, RDW_INVALIDATE); InvalidateRect(win, NULL, NULL); The main question(s): When should I use one or the other? Are there any differ...

How to handle signals when a QT object isn't created through Designer?

Hi I've got a spare moment so decided to look at QT and how easily I can port my windows applications to Qt. My only real problem is a couple of controls that will need re-implementing under QT. I've already handled the basic drawing of the control but my control creates a child scroll bar. The problem is that this scrollbar is crea...

Class with pass-by-reference object gives compile error

I've got a class A defined in a separate header file. I want class B to have a reference to a object of class A stored as a variable. Like this: File: A.h class A { //Header for class A... }; File: B.h #include "A.h" class B { private: (24) A &variableName; public: (36) B(A &varName); }; When i try to co...

make a charater follow an uneven terrain (2D)

I'd like to make a game where the terrain is not even and is based on a png. How s this done in theory, given the object's vec2 and its angle, because if for instance there is a hill, the character will rotate based on the angle of the hill. Thanks 2d like mario ...

Can objects be unwinded before they are created on stack?

We have been debugging a strange case for some days now, and have somewhat isolated the bug, but it still doesn't make any sense. Perhaps anyone here can give me a clue about what is going on. The problem is an access violation that occur in a part of the code. Basically we have something like this: void aclass::somefunc() { try { ...

[C++] Deque of user-defined structures

I've got a user-defined structure struct theName and I want to make a deque of these structures (deque<theName> theVar). However when I try to compile I get this error: In file included from main.cpp:2: Logger.h:31: error: ISO C++ forbids declaration of ‘deque’ with no type Logger.h:31: error: expected ‘;’ before ‘<’ token Why can't I...

Can I ask VC++ linker to ignore unresolved externals?

I'm trying to build a very complex open-source project with VC++. The project consists of dozens of libraries and one executable depending on those libraries. For some reasons VC++ linker doesn't want to see about 40 functions implemented in one of those libraries and reports "unresolved external reference" on each, so I can't link. I d...

How to force template function overload for boost::bind?

Hi, I'm trying to create predicate for std::find_if by using boost::bind together with boost::contains (from boost/algoritm/string library). Following snippet shows two ways how I'm trying to accomplish this. #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> #include <boost/function.hpp> #include <iostream> #include <s...