c++

When to pass by reference and when to pass by pointer in C++?

Common Situations: Passing std::string to a function foo(std::string*) or foo(std::string&); Passing tr1::shared_ptr to a function foo(tr1::shared_ptr* ptr) or foo(tr1::shared_ptr& ptr); In general, what is a good practice. I always get confused. At first, passing everything as references seems consistent, however it is not possible ...

How can my program switch from ASCII to Unicode?

I want to write a program in C++ that should work on Unix and Windows. This program should be able to use both: the Unicode and non Unicode environments. Its behavior should depend only on the environment settings. One of the nice features that I want to have, is to manipulate file names read from directories. These can be unicode... or...

c++ std::string to boolean

I am currently reading from an ini file with a key/value pair. i.e. isValid = true When get the key/value pair I need to convert a string of 'true' to a bool. Without using boost what would be the best way to do this? I know I can so a string compare on the value ("true", "false") but I would like to do the conversion without havin...

Simple reference counting: smart pointers

I would like to implement a simple reference counting using smart pointers. The variable pointer represents pointer to stored object, reference_count represents total count of copies of the object. if we initialize an object using NULL: reference_count = -1 else reference_count = 1 copy ctor and operator = increment reference_count des...

Passing array of structures to function c++

Sorry for the noob question I'm just a little confused. If I have an array of structures in main that I want to pass to a function: struct MyStruct{ int a; int b; char c; mayarray[5]; }; MyStruct StructArray[10]; myFunction(StructArray[]) Pass to this to a function: void myFunction(struct MyStruct PassedStruct...

Converting Objective C formatted code to pure C++

Hi, I've recently started learning programming to make my own 3D OpenGL game on the iPhone and have made reasonably decent progress so far. I started off using the basic OpenGL example that is provided with the iPhone SDK which helped me get off to a good start. However, as I'm starting to get the hang of things, it has occurred to me t...

overhead in addressing 2d array in linear memory space

Does addressing addressing values in a multidimensional array in a linear fashion as in values[row_num*row_width + column_num] incur extra computation for the multiplication/addition when compared to values[row][col]? Or does the compiler convert the latter to the former anyway? ...

What is the Equivalent of Windows WMI for MacOS C++ Development?

I have a C++ application that gets detailed system information (processor type, available disk space, other hardware profile info) on Windows using WMI. I want to perform the same type of operations on OSX 10.5+. What is the equivalent API or interface for MacOS? Links to API documentation or tutorials are very welcome. ...

C++ COM design. Composition vs multiple inheritance

I'm trying to embed a browser control in my application (IWebBrowser2). I need to implement IDispatch, IDocHostShowUI, IDocHostUIHandler etc to make this work. I am doing this in pure C++/Win32 api. I'm not using ATL, MFC or any other framework. I have a main class, called TWebf, that creates a Win32 window to put the browser control in...

What does :: at function name mean?

I saw code like: using namespace zzzz; void XX::YY() { } how does :: work if you write like that? ...

Const pointer argument to a method which delegates to removeAll()

Consider a method like this: void Parent::removeChild(Child *child) { children.removeAll(child); } In this case, since child is never modified itself, one could make it a const pointer. But since children is of the type QList, the removeAll() takes a const reference to a non-const pointer. What's the recommended way to handle thi...

The benefits of C++

Thanks to this website http://unthought.net/c++/c_vs_c++.html and the fact that I build constructor like functions in C, I decided to learn to C++. Besides object-orientated features and templates, what other benefits are there to using C++? Code examples would be great, especially anything creative. ...

Linking c library error. COMDAT symbol '.exc$T' does not match section name '.rdata'

I compiled the speex library for symbian using carbide C++. The compile completes with zero errors/warnings. I use the compiled library in my QT application. Compiling the QT application gives the following error - warning: COMDAT symbol '.exc$T' does not match section name '.rdata' (Its really an error, not a warning. the word warnin...

write time on FTP server is very off

im trying to compare file write times between a local file and a file on an ftp server. the file times on the local machine work and it makes sense, but when I look at the file on the ftp server it shows two different times, via windows explorer and rightclick->properties. I found out a hack that works and its commented in my code. Any h...

Communicating with Windows Process via RPC from a Java application

I'm looking to communicate with a windows process via RPC. The application I want to communicate with is developed in C++ using Visual Studio 2008. The application provides its interface through an idl file which is then compiled using the microsoft midl tool. This application is already developed and cannot be modified. I'm looking to ...

Convert single channle image to 3 channel image C++ / OpenCV

Hi there! Im using openCV C++ Im need to convert a single channel image to 3 channels image. So i can use this: cvCvtColor(result,gray,CV_BGR2GRAY); I cannot do that because the result img is a single channel image. Any ideas? ...

C++ closure hack

is there any problem with such closure implementation (stolen from python hack) void function(int value) { struct closure { closure(int v = value) : value_(value) {} private: int value_; }; closure c; } upon further investigation, it appears in member functions, local variables can not be used as default va...

C++ HTTP interaction that handles JavaScript

Hey people, I have to do some HTTP interaction, which I relied on my own WinInet class so far. Now it comes to handling JS. I have to work with a site that requires JS. No way around it. So what would you suggest for C++ HTTP + JS interaction? I would love something like mechanize (perl, python, etc), that makes whole form interactio...

Prevent default click event (WinAPI)

I'm making a color dropper tool and while this tool is active, when the user clicks or taps I only want it to run my mouse event, not anything else,so while this tool is running,if the user clicks the start orb, it should not open the start menu (or if the user clicks anything else). How could I do this? Thanks ...

Makefile with different rules for .o generation

If I have a rule like this in my make file: CC = g++ CFLAGS = -Wall COMPILE = $(CC) $(CFLAGS) -c src = A.cpp \ main.cpp test_src = Test.cpp test = testAll OBJFILES := $(patsubst %.cpp,%.o,$(src)) TEST_OBJS := $(patsubst %.cpp,%.o,$(test_src)) %.o: %.cpp $(COMPILE) -I UnitTest++/src -LUnitTest++/ -l UnitTest++ -o $@ $< ...