c++

Operator overloading in C++

If you overload - like operator-(), it is to be used to the left of the object, however overloading () like operator()() it is used to the right of the object. How do we know which operator is to be used on the left and which ones to be used on the right? ...

delete[] an array of objects

Hello I have allocated and array of Objects Objects *array = new Objects[N]; How should I delete this array? Just delete[] array; or with iterating over the array's elements? for(int i=0;i<N;i++) delete array[i]; delete[]; Thanks UPDATE: I changed loop body as delete &array[i]; to force the code to compile. ...

Casting array of pointers to objects

If B is subclass of A. And I have in main(): B** b = new B*[10]; ... // some algorithm that does b[i] = new B(..); So I have an array of pointers to objects B. Then I have a function: void f(A** foo); If in main, I do: f(b); I get a warning, but obviously if I do: f((A**)b);, I don't. The (A**) its a bit nasty. I was wondering i...

Tips on how to deploy C++ code to work every where

I'm not talking about making portable code. This is more a question of distribution. I have a medium-sized project. It has several dependencies on common libraries (eg openssl, zlib, etc). It compiles fine on my machine and now it's time to give it to the world. Essentially build engineering at its finest. I want to make installers...

Why aren't return types considered in Java method overloads?

Why return type of a method is not considered in method overloading ? Can somebody explain , how compiler checks for overloaded methods ? ...

Why do I see THROW in a C library?

When I do: less /usr/include/stdio.h (which is only a C library - nothing to do with C++) I see __THROW after quite a few function declarations. Also, comments above a few functions say that 'This function is a possible cancellation point and therefore not marked with __THROW' What is all this for? throw is meant to be for exception ha...

how to exploit vulnerability of php?

i have never seen a buffer overflow exploit in live action. supporse I have found a server that seems to have vulnerabilities. Where can i get proof of the concept code preferably in c/c++ to exploit the vulnerability? eg i found this vulnerability Multiple directory traversal vulnerabilities in functions such as 'posix_access()'...

Extra leading zeros when printing float using printf?

I'd like to be able to write a time string that looks like this: 1:04:02.1 hours using printf. When I try to write something like this: printf("%d:%02d:%02.1f hours\n", 1, 4, 2.123456); I get: 1:04:2.1 hours Is it possible to add leading zeros to a float formatting? ...

WTL CSplitterWindow cannot create more than 3 instances?

Hello all, I'm using WTL to create a window containing many splitted panes. The following will be the result. --------------------------- | | | | | | | | | | | | | |-------------------- | | | | | | | | --------------------------- T...

Design question - loading info from DB

I need to build a class that will represent a row in some table in DB (lets say the table is 'Subscriber' and so is the class). I can have the class Subscriber which constructor receives the Objectkey of subscriber, retrieves info from DB and initializes its members. I add another class - SubscriberLoader which have a static method 'Lo...

invasive vs non-invasive ref-counted pointers in C++

For the past few years, I've generally accepted that if I am going to use ref-counted smart pointers invasive smart pointers is the way to go -- However, I'm starting to like non-invasive smart pointers due to the following: I only use smart pointers (so no Foo* lying around, only Ptr) I'm starting to build custom allocators for ea...

Can i pass auto_ptr by reference to functions?

is the following function OK: void DoSomething(auto_ptr< … >& a).... ...

How do I prevent flickering on CListCtrl?

I'm using a CListCtrl/CListView report view (LVS_REPORT) in virtual mode (LVS_OWNERDATA) with LVS_EX_DOUBLEBUFFER enabled and I encounter ugly flickering. Double buffer have a real effect but it doesn't stop all flickering (without it very slow). I'm not looking for switching to other controls that would require a high amount of rework ...

User defined conversion operator as argument for printf

I have a class that defined a user defined operator for a TCHAR*, like so CMyClass::operator const TCHAR*() const { // returns text as const TCHAR* } I want to be able to do something like CMyClass myClass; _tprintf(_T("%s"), myClass); or even _tprintf(_T("%s"), CMyClass(value)); But when trying, printf always prints (null) ...

breaking out from socket select

I have a loop which basically calls this every few seconds (after the timeout): while(true){ if(finished) return; switch(select(FD_SETSIZE, &readfds, 0, 0, &tv)){ case SOCKET_ERROR : report bad stuff etc; return; default : break; } // do stuff with the incoming connection } So basically for ...

Linux C++: how to profile time wasted due to cache misses?

I know that I can use gprof to benchmark my code. However, I have this problem -- I have a smart pointer that has an extra level of indirection (think of it as a proxy object). As a result, I have this extra layer that effects pretty much all functions, and screws with caching. Is there a way to measure the time my CPU wastes due to c...

microsoft visual studio 2008 builds keep failing

My builds keep failing with the following error Project : error PRJ0002 : Error result 31 returned from 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe'. I find that i have to kill some process called mspdbsrv.exe description:"microsoft program database" Then rebuild the entire project. This is annoying. Is there a perma...

Memory allocation problem C/Cpp Windows critical error

Hi! I have a code that need to be "translated" from C to Cpp, and i cant understand, where's a problem. There is the part, where it crashes (windows critical error send/dontSend): nDim = sizeMax*(sizeMax+1)/2; printf("nDim = %d sizeMax = %d\n",nDim,sizeMax); hamilt = (double*)malloc(nDim*sizeof(double)); printf("End hamilt alloc. ...

How can I make this function act like an l-value?

Why can't I use the function ColPeekHeight() as an l-value? class View { public: int ColPeekHeight(){ return _colPeekFaceUpHeight; } void ColPeekHeight( int i ) { _colPeekFaceUpHeight = i; } private: int _colPeekFaceUpHeight; }; ... { if( v.ColPeekHeight() > 0.04*_heightTable ) v.ColPeekHei...

Array: mathematical sequence

An array of integers A[i] (i > 1) is defined in the following way: an element A[k] ( k > 1) is the smallest number greater than A[k-1] such that the sum of its digits is equal to the sum of the digits of the number 4* A[k-1] . You need to write a program that calculates the N th number in this array based on the given first eleme...