c++

Will it leak if delete using base-class pointer?

Given two classes have only primitive data type and no custom destructor/deallocator. Does C++ spec guarantee it will deallocate with correct size? struct A { int foo; }; struct B: public A { int bar[100000]; }; A *a = (A*)new B; delete a; I want to know do I need to write an empty virtual dtor? p.s. I have tried g++ and vc++2008 and...

C++ app: modules design

Hi My app contains several modules (big classes) like network io, data storage, controls, etc. Some of them can cooperate. What would be a good way of declaring and binding the modules? I see several possibilities: 1) All modules declared as global, so we have in main.cpp #include ... ModuleA a; ModuleB b; ModuleC c; and if a wants ...

DLL redirection using manifests

Hi, I need to reliably redirect an applications look up of a specific DLL. Using the app.exe.local approach does not work because local files are ignored if the application has a manifest (embedded or separate file). So I am trying to do DLL redirection by defining the DLL as a private assembly in the manifests. I have a test applicati...

Capturing network status change event

I am trying to get events when the internet connection is reestablished after it is lost. It is for a data transfer software that I am developing. If I lose the network during data transfer, I would like to be notified when it is back and continue the transfer automatically. I can of course create a separate thread and check the network...

Redefine Virtual Functions between header files in C++

Hi, I have one header file which uses a virtual function. This is declared and defined: #ifndef HeaderH #define HeaderH class Base { <some code> public:virtual int checkVal(int& val) { return val;} }; #endif I have another header file which declares some functions, and inherits from this base header. Finally, I have the impleme...

How can I forcibly restart/reload a Playback device programatically in Windows?

By forcibly I mean even when some audio applications are using it. By reload I mean the kind of thing that happens after the shared mode sample rate of the speaker is changed in the advanced tab of Speaker Properties. Any audio applications stop immediately. Is it possible to do such a restart programatically? (Or even for that matter ...

Why is QMutex unknown?

I've included the QMutex header and using it as seen below. But I get the following error: error C2146: syntax error : missing > ';' before identifier > '_RecorderParamsMutex' error C4430: missing type specifier - int assumed. > Note: C++ does not support default-int error C4430: missing type specifier -> int assumed. ...

Will C++ exceptions safely propagate through C code?

I have a C++ application that calls SQLite's (SQLite is in C) sqlite3_exec() which in turn can call my callback function implemented in C++. SQLite is compiled into a static library. If an exception escapes my callback will it propagate safely through the C code of SQLite to the C++ code calling sqlite3_exec()? ...

Experience with IBPP interface for Firebird database

I'd like to the ask guys with experience in Firebird and IBPP (especially the latter). I found a lot of positive posts about Firebird but I'm having a problem to decide about IBPP. The interface itself is clean and simple but it seems that the project does not have much of activity going on (maybe because it's very stable). Would you r...

Mac OS X. No such file or directory for Lua framework.

I have Cocoa project which uses Lua.framework. In the header file I try to include some .h files from this framework: ... #include <lua.h> #include <lauxlib.h> #include <lualib.h> ... And when I compile the source file I get this error: error: lua.h: No such file or directory error: lauxlib.h: No such file or directory error: lualib...

boost serialization issue with shared_ptr to std containers

Hi I am using boost/1.41.0, and the following code give me compilation error when I try to deserialize a shared_ptr. The serialize part it compiled successfully. Can someone advise me if this is a bug in my code or a general issue for boost? Thanks. Yanchao #include <iomanip> #include <iostream> #include <cstddef> // NULL #include <fst...

Implementation of a work stealing queue in C/C++?

I'm looking for a proper implementation of a work stealing queue in C/CPP. I've looked around Google but haven't found anything useful. Perhaps someone is familiar with a good open-source implementation? (I prefer not to implement the pseudo-code taken from the original academic papers). ...

Why can't for_each modify its functor argument?

http://www.cplusplus.com/reference/algorithm/for_each/ Unary function taking an element in the range as argument. This can either be a pointer to a function or an object whose class overloads operator(). Its return value, if any, is ignored. According to this article, I expected that for_each actually modifies the objec...

How to write a Cocoa OpenGL app in C++?

I'm writing an application that needs to use OpenGL, on the Mac, in C++. Is there anyway I can get Cocoa to just give me an OpenGL context and let me do my work in C++? (I want my app to run on both Mac OS X and iPHone; but all the GUI is in OpenGL, I just need a OpenGL context). Thanks! ...

QPainter fails when calling begin

Hi, I'm trying to paint a PNG file on a QsplashScreen. Im' trying to do it via QPaitner. The reason I want to do it via QPainter is because I want it to minimize smoothly (until it disappear), When I'm just repaiting it it doesn't looks smooth at all. I passed the QSplashScreen to the QPainter constructor. When I call begin() in the QPa...

Can a functor retain values when passed to std::for_each?

According to the first answer to this question, the functor below should be able to retain a value after being passed to foreach ( I couldn't get the struct Accumulator in the example to compile, so built a class). class Accumulator { public: Accumulator(): counter(0){} int counter; void operator()(const Card...

vector and const

Hello Consider this void f(vector<const T*>& p) { } int main() { vector<T*> nonConstVec; f(nonConstVec); } The following does not compile.The thing is that vector<T*> can not be converted to vector <const T*> , and that seems illogically to me , because there exists implicit conversion from T* to const T*. Why is this ? v...

Google Chrome selected text

I am trying to get selected text from browsers(ie,opera, firefox..) using my C# application. I tried SendKeys.Send("^c") then reading the selected value from clipboard this method works fine with ie and Firefox.., but it doesn't work with Google Chrome. How can I get the selected text from Google Chrome and why SendKeys.Send("^c") doesn...

Determine if O/S is Windows 7...

Working on a project and need to be able to determine whether the O/S is Windows 7, Vista or default to XP. I understand I could run into Win2K and earlier versions but let's just say that's not a concern as other code will catch that before it gets to this point. My application will be in C++ for the time being using VS2005. I've found ...

(How) can I count the items in an enum?

This question came to my mind, when I had something like enum Folders {FA, FB, FC}; and wanted to create an array of containers for each folder: ContainerClass*m_containers[3]; .... m_containers[FA] = ...; // etc. (Using maps it's much more elegant to use: std::map<Folders, ContainerClass*> m_containers;) But to come back to my or...