c++

C++ unit testing with VS test professional.

Does any one know if I can test native code in VS Test 2010? ...

Working around the char array on stack align problem

See: http://stackoverflow.com/questions/3874615/placement-new-issue Simple question, would this solve the align problem? union { char real_array[sizeof(T)*size]; T fake_array[size]; }; ...

Casting to base class validity

Say I have a class named Base and a class that derives from it called SuperBase. Given that add takes in a Base*, would either of these be valid: SuperBase *super = new SuperBase; bases.add(super); Or SuperBase *super = new SuperBase; bases.add((Base*)super); ...

C++ object without subclasses?

I was wondering if there is a way to declare an object in c++ to prevent it from being subclassed. Is there an equivalent to declaring a final object in Java? ...

Python Metaclass to Parametrize Inheritance

I've read some tutorials on Python metaclasses. I've never used one before, but I need one for something relatively simple and all the tutorials seem geared towards much more complex use cases. I basically want to create a template class that has some pre-specified body, but takes its base class as a parameter. Since I got the idea fr...

What is the best way to do time stamping?

Okay so I would like to do some time stamping down to uS ... mS would be okay too ... but in looking into this, I am thinking What are the BEST PRACTICES when doing time stamping? My assumptions in this case are that C/C++ code is being used. I know internal clocks have various resolutions and the like ... but I am interested in things t...

What does wxWidgets' EVT_CHAR_HOOK do?

I am maintaining a wxWidgets C++ application that uses EVT_CHAR_HOOK to capture key events in a high level window. I can't find any real documentation for this event but I can surmise that it intercepts key events in some way that has priority over the "standard" key events. One disturbing thing that I just discovered is that, if this...

Making size_t and wchar_t portable?

To my understanding the representation of size_t and wchar_t are completely platform/compiler specific. For instance I have read that wchar_t on Linux is now usually 32bit, but on Windows it is 16bit. Is there any way that I can standardize these to a set size (int, long, etc.) in my own code, while still maintaining backwards comparabil...

static library works in console but not in GUI app - strange.

Hi all. I have a strange error that has bothered me all day. I have a library function that I have compiled. I statically link the library to test it in a separate console application and everything builds and works ok. It is just a simple sqrt function called sqrtval at the moment. However, when I include this library in a larger graphi...

Call function after certain time has elapsed

I'm making a GUI API (for games, not an OS) and would like to implement animated buttons. I'd like to be able to create timed events, but, within the class. example: class TextBox { void changeColor(int color); void createTimedEvent(func* or something, int ticks); void animate() { createTimedEvent(changeColor(red),30);...

default d'tor, copy c'tor, operator=

let's assume I have some class A: header class A{ int x; int value() {return x}; }; main A a; cout << a.value(); my question is: will my compiler produce d'tor copy c'tor and operator= for me or not (cause it actually doesn't need it) EDITED does it write d'tor for me at all, cause it seems to be useless, may you give please exa...

in C++ how can I pass a static array to an object as a parameter, and modify the original array in there?

The array has to be on the stack, and I need to modify the elements. Here is what I have: Class Me { private: int *_array; void run(){ for (int i = 0 ; i < 10; ++i) { _array[i] += 100; } } public: Me(int array[]) { _array = array; } }; This is main: int array[10] = {0, 1...

C++ to pyQt movie player Widget conversion example ??

http://doc.qt.nokia.com/4.6/multimedia-videowidget.html http://doc.trolltech.com/4.2/widgets-imageviewer.html I´ve found those links above but I must say I´m not familiar with C++ at all and I could not convert to PyQt ... Would be extremely helpfull if someone could post a simple conversion code here, so I could dig into that. Thanks...

Triangle is taking up whole window?

I am trying to draw a triangle using GL_POLYGON but for some reason it is taking the whole window.. ... typedef struct myTriangle { float tx; float ty; } myTriangle; std::vector<myTriangle> container; void display() { glClear(GL_COLOR_BUFFER_BIT); for(int i = 0; i < (int)container.size(); ++i) { glBegin(GL_POLYGON);...

Will a function pointer be NULL by default?

In the class below, would this mean that onPaintCallback is NULL, or must I make it NULL in the class constructor? I want to start checking for NULL before it is given a valid pointer. class AguiWidgetBase { virtual void onPaint(); void (*onPaintCallback)(AguiRectangle clientRect) = 0; public: AguiWidgetBase(void); ~Agui...

Difference between QSharedPointer and QSharedDataPointer?

Hi, What is the difference between these two types of pointers? As far as I can read, QSharedPointer can handle situation well, so what is the need for QSharedDataPointer? ...

Self destructing objects

Just wondering whether an object can self-destruct. Consider this situation. An object that extends a thread object. Session : Thread { Session() {} ~Session() {} ThreadMain() { while(!done){ /* do stuff ... */ ... // something sets done = true; } ~Client(); } }; void start_session() ...

how to send key's to any application that is currently running from background program (c++)

Hello everyone, my question is how to send some key's to any application from application that is running in background? Let's say that I made shortcut to LEFT ARROW key which is ALT+S, and than I want whenever I'm in any application and when I press ALT+S that background application response that shortcut and send to currently opened pr...

C++ - Big-O Notation

For some reason im unable to solve this. what will be the Big-o Notation for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { c[i][j] = 0; for (int k = 0; k < n; k++) c[i][j] += a[i][k] * b[k][j]; } ...

Rewriting a program without using goto statements

I had to program a similar problem using goto statements. Now we are asked to rewrite our code without using goto statement. I don't know how to begin doing this program. I paste in the previous program code using the goto. // Eight Queens problem using one dimesional array and goto statement #include "stdafx.h" #include <iostream>...