c++

How should I create a child window in win32 while programming with C++?

i'm new to C++ as well as for windows programming.. i have created a window using msdn CreateWindow() function which works correctly..now i would like to create a child window...the parent window should control the child window... Any helps sample code regarding this . Thanks in advance ...

What cast occurs when there is a signed/unsigned mismatch?

When a compiler finds a signed / unsigned mismatch, what action does it take? Is the signed number cast to an unsigned or vice versa? and why? ...

Is there a way to forbid casting to subclass that is non-const in C++?

Here is a complete example. I want to forbid using A::set from objects casted from B to A by allowing only casting B to const A. How to do it? (I can't use virtual functions) #include <iostream> #include <cassert> using namespace std; class A { public: int get() const { return i_; } void set(int i) { i_ = i; } protected: int ...

Throwing Destructors, Memory Corruption?

We have a class whose semantic behaviour is like the following :- struct Sample { ~Sample() throw() { throw 0; } }; void f () { try { delete new Sample; } catch (...){ } } I know that throwing exceptions in dtors is evil; but the relinquishment of a 3rd Party library resource is throwing an exception (but can...

C++ Iterators Considered Harmful?

At the Boost library conference today, Andrei Alexandrescu author of the book Modern C++ Design and the Loki C++ library, spoke about why iterators are bad, and he had a better solution. I tried to read the presentation slides, but could not get much out of them. I have these questions for the StackOverflow community: Are iterators ba...

Call C++ code from a C# application or port it?

I've recently been wrestling with an algorithm which was badly implemented (i.e. the developer was pulled off onto another project and failed to adequately document what he'd done) in C#. I've found an alternative (from numerical recipes) which works but is written in C++. So I'm thinking probably the safest way to get something workin...

How does the compiler resolve infinite reference loops?

// edited by Neil Butterworth to conserve vertical space #include <stdio.h> struct A; struct B; A& GetAInstance(); B& GetBInstance(); struct A { A() { printf( "A\n" ); } ~A() { printf( "~A\n" ); B& b = GetBInstance(); } }; struct B { B() { printf( "B\n" ); } ~B() { ...

Naming: Why should named constants be all uppercase in C++/Java?

I know, that for C++ and Java it is a well established naming convention, that constants should be written all uppercase, with underscores to separate words. Like this (Java-example): public final static Color BACKGROUND_COLOR = Color.WHITE; public final static Color TEXT_COLOR = Color.BLACK; This naming convention is easy to understa...

How do I make a CMFCToolBar recognize image masks?

I have a CMFCToolBar-derived class and an insance thereof is the member of a CDockablePane-derived class. I looked at the VisualStudioDemo sample to see how it's done and have this so far: int CMyPane::OnCreate(LPCREATESTRUCT lpCreateStruct) { // Removed all "return -1 on error" code for better readability CDockablePane::OnCre...

object returned after an exception?

int somefunction(bool a) { try { if(a) throw Error("msg"); return 2; } catch (Error const & error) { //do i need to return anything here?? //return -1; } } ...

Aggregating contributions from multiple donors

As I try to modernize my C++ skills, I keep encountering this situation where "the STL way" isn't obvious to me. I have an object that wants to gather contributions from multiple sources into a container (typically a std::vector). Each source is an object, and each of those objects provides a method get_contributions() that returns any...

Hints and tools for finding unmatched braces / preprocessor directives

This is one of my most dreaded C/C++ compiler errors: file.cpp(3124) : fatal error C1004: unexpected end-of-file found file.cpp includes almost a hundred header files, which in turn include other header files. It's over 3000 lines. The code should be modularized and structured, the source files smaller. We should refactor it. As a ...

How to add search functionality to my application

I am writing Windows application (with Borland C++ Builder), which stores large number of text files. I want users to be able to search these files very fast, so I need an indexing and search library. I do not use database, but my own file format for storing the documents (all are in a single file). Are there such libraries for Windows?...

Get std::fstream failure error messages and/or exceptions

I'm using fstream is there any way to get the failure message/ excpetion. for example if unable to open the file I want to get the reason for it. ...

How much should I worry about the Intel C++ compiler emitting suboptimal code for AMD ?

We've always been an Intel shop. All the developers use Intel machines, recommended platform for end users is Intel, and if end users want to run on AMD it's their lookout. Maybe the test department had an AMD machine somewhere to check we didn't ship anything completely broken, but that was about it. Up until a few of years ago we ju...

qt trouble overriding paintEvent

I'm subclassing QProgressBar in a custom widget, and I overwrote the paintEvent method with the following code : void myProg::paintEvent(QPaintEvent *pe) { QProgressBar::paintEvent(pe); QRect region = pe->rect(); QPainter *painter = new QPainter(this); QPen *pen = new QPen; painter->begin(this); painter->setBrus...

With CDatabase, can I send SQL without using CRecordSet?

When using the MFC class CDatabase to connect to a data source, is there any way to execute SQL statements without having to open a CRecordSet object? I ask because CRecordSet::Open() appears to throw an exception when I use it to call stored procedures that don't return anything - and there's no reason to expect results from, say, sp_d...

The right type for handles in C interfaces

I'm creating a C api that hides some functionality in a DLL file. Since everything is C++ on the inside most of the functions works against handles which maps directly to this pointers on the inside of the API. To get a some degree of type safety for those handles I define them like this: typedef struct MyType1* MyType1Handle; typedef...

Using std:fstream how to deny access (read and write) to the file

How can I deny access to a file I open with fstream? I want to unable access to the file while I'm reading/writing to it with fstream? ...

Custom Iterator in C++

I have a class TContainer that is an aggregate of several stl collections pointers to TItems class. I need to create an Iterator to traverse the elements in all the collections in my TContainer class abstracting the client of the inner workings. What would be a good way to do this?. Should I crate a class that extends an iterator (if ...