c++

Can 'return' return multiple values in C?

Possible Duplicate: C++ return x,y; What is the point? Here's a piece of code that executes perfectly in C. int a=3,b=4,x,y; x=a+b; y=a*b; return(x,y); This function returns 12. Can someone please explain. ...

Macros to avoid heap allocation ? In this case is that bad?

Hello all, It's my first question there, and it's a noobish question :). I'm facing to a problem with C++ and Qt 4.6, because I want to factorize some of my code which is invoking some public slots of a QObject, through the QMetaMethod::invoke() method. The problem I'm facing to, is that the Q_ARG macro is defined as follow: #define ...

example on c++ data member aligment

I have tried to implement this example; here is the code: #include <stdio.h> #include <stddef.h> typedef struct { unsigned char a; unsigned char b; unsigned char c; }foo; typedef struct{ unsigned short i; unsigned char a; unsigned char b; unsigned char c; }Bar; typedef struct {foo f[5];} f_b; typedef struct {B...

Writing cross-platform C++ Code (Windows, Linux and Mac OSX)

This is my first-attempt at writing anything even slightly complicated in C++, I'm attempting to build a shared library that I can interface with from Objective-C, and .NET apps (ok, that part comes later...) The code I have is - #ifdef TARGET_OS_MAC // Mac Includes Here #endif #ifdef __linux__ // Windows Includes Here #error C...

Function with variable arguments

Which disadvantages could I have if I want to use the function foo(int num, ...) to implement the variable number of arguments? I do know the first disadvantage that you can only use one data type. Is there any way else to do that? ...

tr1::unique_ptr and SelectObject()

Hi, I have some original code that manages exception safety like this: void foo() { HDC hdc = //get an HDC HBITMAP hbitmap = //get an HBITMAP HGDIOBJ hbitmapOld = SelectObject(hdc, hbitmap); try { //do something that may throw an exception } catch (...) { SelectObject(hdc, hbitmapOld); thro...

How to create a class that is a widget that has a QTextEdit and a QToolBar above the text edit.

My intent is to create a QTextEdit with its reach text controls. The controls I want to put in a toolbar. But I have difficulties with controling the layout. The problem is that the overlap if I put a QTextEdit in a QWidget (my class inherits QWidget) which has a toolbar. Another way I tried was the following: my class inherits QTextEdi...

create cairo context without a present window object

Hi there, I am currently using libcairomm for graphic stuff in my program. All the internet examples use code like Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context(); But I am using cairo to pass a svg texture to OpenGL Is there a kind of constructor working without that window ? Thank you for the answers :) ...

STL container with more than 1 sorting method in c++

Hello, i am looking for a container, to contain objects like Employee (with info: name, salary, phone ....) that will be possible to once sort it by name (a..z) and other time sort it by salary for example. what is the best way to do it ? i thought about map, but then i define only 1 key to go by would appreciate every idea (not too adva...

What is triple check locking pattern

Reference:- "Modern C++ Design: Generic Programming and Design Patterns Applied" by Andrei Alexandrescu Chapter 6 Implementing Singletons. Even if you put volatile then also it is not guaranteed to make Double Check locking pattern safe and portable.Why it is so? If some one can put any good link that explains what is relaxed memory ...

Why won't my nested QEventLoop deliver all the events for my QThread?

I'm having a problem with QEventLoop. I want to create a "TimeBoundExerciser" for my unit test so that my SUT, which blocks on a QEventLoop, won't block the rest of the test cases. Specifically, my test case is to make sure the SUT terminates after a timeout. The TimeBoundExerciser basically spawns a thread, executes the SUT on that thr...

How to insert an object to a map structure by a certain field?

Hello, i have an object - Employee, and i want to know how to insert this object to a map structure sorted by char* lastName field. Thanx. My map need to contain pointers to Employee objects not the objects themselves. the key is the last name of the employee, the map need to be sorted by the employees last name, should i use multimap? ...

Splitting a word from a read file.

I'm trying to read the contents of a text file into the attributes of a class. The file is structured in such a way that each line contains all the information needed for one object of the class. One line might look like: TYC 9537 00066 1 341.76920751 -88.32499920 8.762 9.294 mc1 hd 210531 0.385 8.80 P F5 5 6440 F5 V What...

Global Variable within Multiple Files

I have two source files that need to access a common variable. What is the best way to do this? e.g.: source1.cpp: int global; int function(); int main() { global=42; function(); return 0; } source2.cpp: int function() { if(global==42) return 42; return 0; } Should the declaration of the variable glob...

Replacement for <conio.h> in Linux

I need to transfer a windows C++ project to linux, however I am currently using MS <conio.h> which is not linux or standards compatible. What header do you recommend to replace it for use in Linux? I would prefer the answer is cross platform too. ...

Marshalling between C# and C++, and the Juggling of Responsibilities

Hello everybody, what if I had a native C++ function in which, depending on the result of the function, the responsibility of deleting a certain pointer (delete[]) differs between the caller and the function. I would of course check for the return value and act accordingly in C++. Question is, what if the function was marshalled between...

STL "closest" method?

I'm looking for an STL sort that returns the element "closest" to the target value if the exact value is not present in the container. It needs to be fast, so essentially I'm looking for a slightly modified binary search... I could write it, but it seems like something that should already exist... ...

shared_ptr: horrible speed

When comparing two variants of pointers (classic/shared_pt) I was surprised by a significant increase of the running speed of the program. For testing 2D Delaunay incremental Insertion algorithm has been used. Compiler settings VS 2010 (release) /O2 /MD /GL, W7 Prof, CPU 3.GHZ DualCore Results: shared_ptr (C++ 0x00): N[points] ...

Win32 - Fullscreen popup menu temperamental activation

Using C++ in VS2008, I'm at the beginnings of a DirectX program which can so far display a token image and flip between fullscreen and windowed mode with no problems. It has a menu bar, which is invisible as expected in fullscreen mode. The ALT key could still activate this menu in fullscreen, but it was very clumsy since its items wer...

MySQL error 2005 (using MySql C++ Connector):

I am trying to connect to a database using MySQL C++ Connector. I have used this code segment many times: driver = get_driver_instance(); connection = driver->connect("tcp://127.0.0.1:3306", "user", "pass"); and it has worked successfully, but now I am getting this error thrown from this code segment: "Unknown MySQL server host 'ÇD$Œ...