c++

Convert UTF-16 to UTF-8

I am current using VC++ 2008 MFC. Due to PostgreSQL doesn't support UTF-16 (Encoding used by Windows for Unicode), I need to convert string from UTF-16 to UTF-8, before store it. Here is my code snippet. // demo.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "demo.h" #include "Utils.h" #incl...

Why does this work?

hi, I have just been working with boost::bind and boost::function and noticed the following behaviour (which I thought was a bit odd). You can bind a function with fewer parameters than required by the boost::function type! It appears as though any additional parameters are simply ignored and just fall away. So why is this behaviour co...

Is there a way to 'expand' the #define directive?

I have a lot of "stupid" #define in a project and i want to remove them. Unfortunately, i can't do a simple search&replace, since the #define is parametrized. For example: #define FHEADGRP( x ) bool _process_grp##x( grp_id_t , unsigned char ) This is used to generate headers of a couple of functions. I would like to somehow do the sam...

when returning by address, doesnt this go out of scope? ( SDL question)

Hi there, this is a code example from lazyfoo's SDL tutorials. SDL_Surface *load_image( std::string filename ) { //Temporary storage for the image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image loadedImage = SDL_LoadBMP( filename.c_str()...

Only implement copy constructor, no assignment constructor

Hi all When the class with a member which is a pointer, we need implement a copy constructor for it. I have a question, if we have implemented a copy constructor, should we implement an assignment constructor too? Best Regards, ...

Preventing compilers from defining copy constructors and operator = overload for C++ Classes

Is there a way by which we can prevent compilers from defining copy constructors, operator = overload for C++ classes. ...

When are global static const variables being initialized?

Hello all, I tried to search the site for this question but didn't find this exactly, although this subject is being discussed a lot... I have this declaration in a cpp file, not within any function: static const char* gText = "xxxxxxxxxxx"; Although it has a fixed size, I get a warning from a static analysis tool (Klocwork) when I'm...

Return-type polymorphism for pass-by-value

I'm not sure if the question title is accurate... Let me start by explaining my original simple scenario, and then move on to explain what would I like to do, but can't. Originally, I had something like: class Operand; Operand genOperandA() { ...; return Operand(); } Operand genOperandB() { ...; return Operand(); } ... // more operand...

int to string conversion

I would like to save files with different names in a loop. I use a library that needs a char as a parameter of the file... for(int i=0;i<nodes;i++){ for(int j=0;j<nodes;j++){ char a[20]="test"; char c[20]="xout.dat"; Lib::SaveFile(_T(a), _T(c)); }} The above code works, but I would like to change the name of the xout.mid to th...

exception handling

Is there any section in c++ for which we can not handle exceptions? ...

Why? Implicit initialization from uninitialized parent class members

I had a nasty experience with C++ initialization, and I'm trying to see whether there is a real-world example which justifies no warnings from the compiler. The following code compiles correctly, but foo and bar get initialized with uninit values (I assume from the uninitialized parent class). The compilers, both g++ and VS, don't emit ...

A good repartition algorithm

Hi, I am implementing a memcached client library. I want it to support several servers and so I wish to add some load-balancing system. Basically, you can do two operations on a server: Store a value given its key. Get a value given its key. Let us say I have N servers (from 0 to N - 1), I'd like to have a repartition function whic...

C++ XUL Frameworks

What are the most popular XUL Frameworks for C++. I am interested in both X Platform and also Platform Dependant ones. Cheers, Andrew ...

Const char conversion error.

Hi, I am getting the following error with gcc. invalid conversion from ‘char**’ to ‘const char**’ With this code. void foo( const int &argc, const char **argv ); int main( int argc, char *argv[] ) { foo( argc, argv ); } Why is this? ...

Why and when is worth using pointer to pointer?

Possible Duplicate: How do pointer to pointers work in C? Hello, Altough I think I passed the newbie phase in programming I still have some questions that somehow I can't find them explained. Yes, there are plenty of "how to"s overthere but almost always nobody explains why and/or when one technique is useful. In my case I h...

Looking for any good(and free) cross-platform CLI parsing library for a command line utility

I am currently working on a CLI utility which I feel can be improved a lot by adding a framework. Basically the utility revolves around lots of command line syntax AND parsing the output. Currently the code is scattered all around with lots of individual inhouse run() and readFromRunOutput() calls with hardcoded CLI arguments. For exa...

Problem using templated predicate in STL algorithms

I have the following piece of code, that gives an error on the first usage form of pred2. I was hoping if someone could explain why this particular usage is incorrect, as I think pred3 usage is similar. #include <algorithm> bool pred1(const int&) { return true; } template<typename T> bool pred2(const T&) { return true; } struct pred3...

Dividing large integer by large integer

Guys I'm working on class called LINT (large int) for learning purposes, and everything went ok till know. I'm stuck on implementing operator/(const LINT&). The problem here is that in when I want to divide LINT by LINT I'm getting into recursive fnc invocation i.e: //unfinished LINT_rep LINT_rep::divide_(const LINT_rep& bottom)const {...

best practice for implementing a Search-Function via prepared statements.

I'm trying to implement a Search-Function using c++ and libpqxx. But I've got the following problem: The user is able to specify 4 different search patterns (each of them optional): from date till date document type document id Each of them is optional. So if I want to use prepared statements I would need 2^4 = 16 different prepared ...

meaning of 'operator' in this C++ statement

What does the 'operator' mean in this C++ usage? char* pszVar= W2A(_bstr_t(bstrVar).operator wchar_t*()); ...