c++

Instantiating at global level (C++)

Hi, I get the following error with the code below. expected constructor, destructor, or type conversion before '=' token -- #include <string> #include <map> class Foo { }; std::map<std::string, Foo> map; map["bar"] = Foo(); int main() { return 0; } ...

Python, Perl And C/C++ With GUI

Hello, I'm now thinking, is it possible to integrate Python, Perl and C/C++ and also doing a GUI application with this very nice mix of languages? ...

GetDlgItemInt( ) problem

Ok, i have 2 edit controls and a button in my main window; in one edit control the user can write a number and when he push the button i read that number and i print it in the other edit control (which is read only). My problem is that when i put a number and i press the button, for some reason that i dont understand i can get that numb...

Static inline methods?

Okay, Here is what I'm trying to do... Right now it is compiling but failing at linking... LNK2001 I want the methods static because there are no member variables, however I also want them inline for the speedups they provide. What is the best way to do this? Here is what I have in a nutshell: /* foo.h */ class foo { static vo...

array initialisation

Hi all, I'm quite certain that arrays of built in types are unitialized, whereas arrays of UDTs are default initialized. int foo[5]; // will contain junk Foo foo[5]; // will contain 5 Foo objects that are default initialized This occurs regardless of whether the array is allocated on the stack or heap. However, I'm finding it hard ...

Boost multi-index container with index based on nested values

If I have an object like this: struct Bar { std::string const& property(); }; I can create a multi-index container for it like this: struct tag_prop {}; typedef boost::multi_index_container< Bar, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::tag<tag_prop>, boost::multi_index...

null objects vs. empty objects

[ This is a result of Best Practice: Should functions return null or an empty object? but I'm trying to be very general. ] In a lot of legacy (um...production) C++ code that I've seen, there is a tendency to write a lot of NULL (or similar) checks to test pointers. Many of these get added near the end of a release cycle when adding a N...

Finding symbols for C++ source file

Hi, I have a project that is C++ WIN32 project. I found a problem that some symbol can be recognized by the windbg but some don't. I don't know why. The characteristics are: 1) both are C++ method 2) both function are in one .cpp file 3) the two functions are very close in the source file and neither of them are enclosed by a #...

printing using one '\n'

I am pretty sure all of you are familiar with the concept of the Big4, and I have several stuffs to do print in each of the constructor, assignment, destructor, and copy constructor. The restriction is this: I CAN'T use more than one newline (e.g., ƒn or std::endl) in any method I can have a method called print, so I am guessing print...

Yet another unit testing / code coverage question. Is my approach sane?

This is yet another Unit Testing question. I'm trying to draw knowledge from a number of places regarding how to proceed, and I wanted to bounce my current understanding off of the collection of experts here. assume a project for which all dependencies except opengl funkiness are statically linked (except the c run time) My current un...

Why does an overridden function in the derived class hide other overloads of the base class?

Consider the code : #include <stdio.h> class Base { public: virtual void gogo(int a){ printf(" Base :: gogo (int) \n"); }; virtual void gogo(int* a){ printf(" Base :: gogo (int*) \n"); }; }; class Derived : public Base{ public: virtual void gogo(int* a){ printf(" Derived :: gogo (int*) \n...

Memory mapping physical disks and volumes

In Windows it's possible to open devices and volumes via CreateFile(). I've used this successfully before to ReadFile() from devices, but now I want to switch to memory-mapping. In the following code, I receive INVALID_HANDLE_VALUE for the value of b, and c is set to 87, ERROR_INVALID_PARAMETER. HANDLE a = ::CreateFileA("\\\\.\\h:", GEN...

To write a bootloader in C or C++?

I am writing a program, more specifically a bootloader, for an embedded system. I am going to use a C library to interact with some of the hardware components and I have the choice of writing it either in C or C++. Is there any reason I should choose one over the other? I do not need the object oriented features of C++ but it does have a...

How do you get the icon, MIME type, and application associated with a file in the Linux Desktop?

Using C++ on the Linux desktop, what is the best way to get the icon, the document description and the application "associated" with an arbitrary file/file path? I'd like to use the most "canonical" way to find icons, mime-type/file type descriptions and associated applications on both KDE and gnome and I'd like to avoid any "shelling ...

Whitespace at end of file causing EOF check to fail in C++

I'm reading in data from a file that has three columns. For example the data will look something like: 3 START RED 4 END RED To read in the data I'm using the following check: while (iFile.peek() != EOF) { // read in column 1 // read in column 2 // read in column 3 } My problem is that the loop usually does on extra ...

C++ template specialization without default function

Hello, I have the following code that compiles and works well: template<typename T> T GetGlobal(const char *name); template<> int GetGlobal<int>(const char *name); template<> double GetGlobal<double>(const char *name); However I want to remove the "default" function. That is, I want to make all calls to GetGlobal<t> where 't' is not...

GCC compile error : declaration of ‘strlen’ must be available

My problem is that when I want to make a downloaded library I get some weird compile errors from GCC and the code that the compiler demands to correct seems just to be right. The errors are all like this: Catalogue.h:96: error: there are no arguments to ‘strlen’ that depend on a template parameter, so a declaration of ‘strlen’...

Pointer to a Qt Slot

Hi, i want to build a pointer to a Qt Slot: union { void (*set_slot)(unsigned long value); void (*refresh_slot)(void); } the_slot; The slot definition is: void set_pwm(unsigned long new_pwm); I try to do something like this: the_slot.set_slot = set_pwm; But the compiler says that the signature does not match: error:...

Account memory usage with custom allocator

I'm using a custom allocator to account for memory usage in several containers. Currently I use a static variable to account for the memory usage. How could I separate this account across several containers without having to rewrite the allocator to use different static variables? static size_t allocated = 0; template <class T> ...

When and how to use GCC's stack protection feature?

Hello, I have enabled the -Wstack-protector flag when compiling the project I'm working on (a commercial multi-platform C++ game engine, compiling on Mac OS X 10.6 with GCC 4.2). This flag warns about functions that will not be protected against stack smashing even though -fstack-protector is enabled. GCC emits some warnings when buildi...