c++

sort() function in C++

Hi, I found two forms of sort() in C++: 1) sort(begin, end); 2) XXX.sort(); One can be used directly without an object, and one is working with an object. Is that all? What's the differences between these two sort()? They are from the same library or not? Is the second a method of XXX? Can I use it like this vector<int> myvector ...

Visual Studio resource editor: there can only be one string table?

I created a string table in my .rc file containing my English strings - now I need to add another string table for a different language. If I try to do: Add Resource... -> String Table -> New I get the error: "there cannot be more than one instance of this type". I know I can open up the .rc file in notepad and add language in th...

How do I create a non managed Windows GUI in Visual C++?

When I create a 'Windows Forms Application', the resultant program is a managed one. Creating a 'Win32 Application' results in a native one, but when I try to add a form I'm informed that the project will be converted to CLI if I continue. How do I design a native Windows GUI with Visual C++ 2008 Express Edition? I'm probably being very ...

C++ GUI Tutorial: undefined reference to TextOut

So after a bit of searching for Win32 GUI tutorials (I decided a tutorial on making GUIs might make me more active in making C++ applications and therefore stronger at programming in C++ in general,) I came across a rohitab tutorial. There are two parts that I have been able to find. Part 1 worked fine, and I'm now working on Part 2, how...

How to use ALSA's snd_pcm_writei() ?

Hi everybody, Can someone explain how snd_pcm_writei snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size) works? I have used it like so: for (int i = 0; i < 1; i++) { f = snd_pcm_writei(handle, buffer, frames); ... } Full source code at http://pastebi...

Draw World Map [WGS84] with OpenGL in a wide Range

hi I've got a quite specific problem. I want to draw a Map, consisting of 256x256 pixle Tiles (a lot of them). These cover a big area. The transformation to convert lat|lon(from the globe) to x|y (map) spawns quite big values. With these big values goes accurcy and so, if I go far away from the 0/0 Point, I get inaccuracies of multiple...

C++ Seg fault on reference to stored base class pointer

Hi all. I'm getting some nasty segmentation faults through the g++ compiler on the following code. Any ideas on why this would happen and how to fix it would be great. #include <iostream> using namespace std; class Base { public: Base() {} virtual ~Base() {}; virtual int getNum(int) = 0; }; class Derived: public Base { public: ...

Finite State Machine : Bad design?

Are Finite State Machines generally considered as bad design in OOP ? I hear that a lot. And, after I had to work on a really old, undocumented piece of C++ making use of it, I tend to agree. It was a pain to debug. what about readability/maintainability concerns? ...

Standard Keyboard Driver Source Code - Where can I find this???

Hello, I am looking for the standard source code for a keyboard. Is there any where that I can download this source code so that I can modify it for my own use? Thanks in advance! ...

utf-8 to/from utf-16 problem

I based these two conversion functions and an answer on StackOverflow, but converting back-and-forth doesn't work: std::wstring MultiByteToWideString(const char* szSrc) { unsigned int iSizeOfStr = MultiByteToWideChar(CP_ACP, 0, szSrc, -1, NULL, 0); wchar_t* wszTgt = new wchar_t[iSizeOfStr]; if(!wszTgt) assert(0); Mult...

Undefined Symbols

The Image class is a subclass of the BMP class. I am attempting to use some methods TellHeight(), TellWidth(), etc. from the BMP class in order to manipulate an image in this method. However, when I create a BMP and attempt to call functions on it, upon compilation I get an error saying Undefined Symbols: BMP::BMP(), reference...

C++ Compiler error with CRTP

I have the following class hierarchy: template <typename T> class base { public: void f() {} }; class class_a : public base<class_a> {}; class class_b : public base<class_b>, public class_a { using base<class_b>::f; }; int main() { class_b b; b.f(); return 0; } Comeu and Intel C++ v11 claim all is...

In C++, how do you print out several lines of text to the console?

Let's say you wanted to print out one of those great ascii art images. How can you do that without "cout"ing each line individually? ...

How to use Redis within a C++ program?

What would be the best way to use a Redis DB within a C++ program? ...

Select mutex or dummy mutex at runtime

I have a class that is shared between several projects, some uses of it are single-threaded and some are multi-threaded. The single-threaded users don't want the overhead of mutex locking, and the multi-threaded users don't want to do their own locking and want to be able to optionally run in "single-threaded mode." So I would like to ...

Need basic help parsing a string in C++

C++ is not my preferred language. I have a file that contains this: e 225,370 35,75 I want to separate e, 225, 370, 35 and 75 from each other into a char and ints but I'm having trouble. I tried doing everything I found online and in my C++ book and still it's not working out. Please help. I would have an easier time doing this in...

Help understanding multidimensional array and pointer notation in c++

I understand the basic idea that when an array is the sole operand of the & or sizeof() operator, it decays to a pointer to the first element in the array. I'm unsure how these notations work though. In our text, there is the 1-D case, vs the 3-D case for an array. The first example is the function declaration for a function called av...

Identical Class Member Names and Function Argument Names in C++

I have a simple object that holds some [public] data. I want to keep my interface clean, so I don't want to pre-/post- fix anything to the names of the publically accessible variables nor to the names of my function arguments. That said, I ended up doing something like this: template<typename T> struct Foo { explicit Foo(T x) : x(x)...

Qt::What needs to be included in the configuration to use dbus?

I'm using stripped down as much as possible configuration of Qt but now I need to use the dbus and can't figure out what I need to include to be able to use it? There doesnt seem to be anything obvious to me using the qconfig tool. The errors I get at the moment when making are: qdbus_symbols.cpp:53: error: expected initializer before ‘...

Is there a way to find the cardinality (size) of an enum in C++?

Could one write a function that returns the number of elements in an enum? For example, say I have defined: enum E {x, y, z}; Then f(E) would return 3. ...