c++

c++, protected abstract virtual base pure virtual private destructor

So, I found this quote today, can anyone explain? "If you think C++ is not overly complicated, just what is a protected abstract virtual base pure virtual private destructor and when was the last time you needed one? — Tom Cargill" ...

Mapping COM VARIANT Types to actual types using a map

I am writing a COM wrapper for a COM object that sends different types of values from a client and want to map these types in a Map to their actual C++ type, such as VT_BSTR to a wstring, etc. I was thinking of defining an enumuration of all COM Variant types and then using a map to have that Enum as the key and the actual type containi...

is there a loop controlled by time in c++?

Hi, I am wondering if I can loop x times in one minute interval between each loop. for (int x = 10; x > 0; x--) { cout << "BOOM" << endl; } Is there any way I can print boom every one minute? Or there is a better way to do this? Thank you ...

Can a C++ compiler optimize away code when dealing with pointers?

Hello, With these two questions as background (first and second), I got curious about how much optimization a C++ compiler can perform when dealing with pointers? More specifically, I'm interested in how smart a compiler is when it optimizes away code which it may detect will never be run. (Some may point out that this is a dupe of thi...

Qt - widget - update

Hi, I am having a widget with a push button. I want, for every click on the push button one label should be added in the widget. I am giving the code below, but is not working. I don't know why. Somebody help me? class EditThingsWindow:public QWidget { QPushButton * add; Q_OBJECT public: EditThingsWindow(); public slots: void addBut...

Confusing output?

I fail to understand is why does the code print '3' in VS2010 (release build), whether I leave the declaration of 'r' or comment it out. int main(){ int arr1[2]; int &r = arr1[0]; int arr2[2]; cout << (&arr1[1] - &arr2[0]); } So, three questions: a. why does the code print 3? b. why does it print 3 even if the decla...

how to store larger binary numbers in bitset (C++)

i m trying to make a program to convert a number into it's binary. Code: #include<iostream> #include<algorithm> #include<bitset> using namespace std; int main() { int a; string k; bitset<CHAR_BIT> n; cin>>a; n=bitset<CHAR_BIT>(a); cout<<n<<" "; return 0...

"x = ++x" is it really undefined?

I am using Coverity on a project to find errors. It reports an error for this expression (The variable names are of course changed): x= (a>= b) ? ++x: 0; The message is: EVALUATION_ORDER defect: In "x=(a>= b) ? ++x: 0;", "x" is written in "x" (the assignment LHS) and written in "(a>= b) ? ++x: 0;" but the order in which the...

Maximum number of fields for a C++ object

This answer states that in Java the maximum number of fields an object may have is 65536. Is there any such limit imposed on an object in C++? ...

Const incorrectness.

Why am I getting this error: Error 1 error C2662: 'Allocator::Allocate' : cannot convert 'this' pointer from 'const Allocator' to 'Allocator &' ? Thats code: /*Allocator.h*/ /*Not finished yet but working*/ #pragma once template<class T> class Allocator { public: //typedef T value_type; typ...

What is the preferred way of allocating C++ class member data?

Let's say I have a class that allocates some arbitrary member data. There are two common ways that I have seen used (I know that there are others): class A { public: A(); ~A(); //Accessors... private: B *mB; } A::A() { mB = new B(); } A::~A() { delete B; } Versus... class A { pub...

Append integer to end of const char* c++

I have const char* FilePathName which looks like this: C:\ImportantFile.hex And an int id = 12345; I need to define a new const char* FilePathName_ID that would append the id with an underscore to the original FilePathName to look like this: C:\ImportantFile_12345.hex I have looked at this but its different as I am using const char* wh...

C++: Binding class functions in DLLs

I'm relatively new to DLL importing and function binding. Let's say I have a C++ project which is a GUI library written fully in OOP aiming to be used in games. My game project however is written in Delphi. I now want to bind Delphi functions to the ones in the DLL. I would know how to do this with simple functions, without classes lik...

Singleton in my C++ program

I wrote 2 classes, Agent and Timing. The third class will contain the main() function and manage it all. The goal is to create n instances of Agent and a SINGLE instance of Timing. It's important to mention that Agent uses Timing fields and Timing uses Agent functions. How can I turn Timing to singleton? //Agent.h #ifndef Timing_h #defi...

Smart pointers, or "better" destructor

Which type of the smart pointer (shared, scoped) would be for such a data structures the most suitable... Structure 1: //Class with cross-references to points p1, p2 class PointTopo { private: double x, y; PointTopo * p1; PointTopo * p2; public: PointTopo(double xx, double yy): x(xx), y(yy) {this-> p1 = NULL; this->p...

Minimizing Sum of Distances: Optimization Problem

The actual question goes like this: McDonald's is planning to open a number of joints (say n) along a straight highway. These joints require warehouses to store their food. A warehouse can store food for any number of joints, but has to be located at one of the joints only. McD has a limited number of warehouses (say k) available, and w...

C++ and Java objects communication

Hi Folks, I need to establish a communication model between C++ layer and Java layer in my application. Initially, I planned to use SOAP with XML, but my clients are interested in setting up a database communication channel. I am new to DB and not sure how to proceed. I would like to take your sincere suggestions on the implementation ...

How do I get started writing a daemon process in a Unix-like operating system, like Linux?

I am doing a tool in PHP for my personal use. But PHP is very slow and the task I need to do is takes much time, so I'll make a daemon in c++ and keep it in the background (It will run in a VPS). PHP would connect to the daemon througt a simple tcp socket (I'll try to design/use a simple IPC protocol) in order to submit the task. The d...

When can optimizations done by the compiler destroy my C++ code?

Hello, When can optimizations done by the compiler cause my C++ code to exhibit wrong behaviour which would not be present had those optimizations not been performed? For example, not using volatile in certain circumstances can cause the program to behave incorrectly (e.g. not re-reading the value of a variable from memory and instead o...

Is there any library that gives access to PC (windows) microphone in a way Open CV gives access to camera?

So in Open CV we have such easy way of getting to some camera device and its data: #include "cv.h" #include "highgui.h" #include <stdio.h> // A Simple Camera Capture Framework int main() { CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY ); if( !capture ) { fprintf( stderr, "ERROR: capture is NULL \n" ); getchar(); re...