c++

Is there a way to include a header in every compilation unit without modifying every source file?

Given the following: large project with thousands of C++ source files no common header file (no one header that's included in every source file) said project is compiled with g++ and managed by make Is there any way to include a definition (e.g. macro) into every compilation unit without modifying every source file to include a new h...

What is the best way to handle multiple object dependencies in C++?

I'm building a C++ application, and I've got several utility objects that all of my classes need to use. These are things like the logging object, the global state object, the DAL object, etc... Up until this point, I've been passing all of these objects around as references into my class constructors. For example: class Honda : p...

Exporting functions from C++ dll to C# P/Invoke

I have built a C++ dll that I would like to call from C# code. I'm able to call one function, but the other throws an exception when the C# code tries to load the dll. The header looks like this: extern "C" __declspec(dllexport) BOOL Install(); extern "C" __declspec(dllexport) BOOL PPPConnect(); This produces a dll with slightly conf...

container for quick name lookup

I want to store strings and issue each with a unique ID number (an index would be fine). I would only need one copy of each string and I require quick lookup. I check if the string exist in the table often enough that i notice a performance hit. Whats the best container to use for this and how do i lookup if the string exist? ...

Why should/shouldn't I use the "new" operator to instantiate a class, and why?

I understand that this may be construed as one of those "what's your preference" questions, but I really want to know why you would choose one of the following methods over the other. Suppose you had a super complex class, such as: class CDoSomthing { public: CDoSomthing::CDoSomthing(char *sUserName, char *sPassword) ...

How to use the Unit test tool comes with VS2008 Pro to test a C++ proj?

Here's what i've done: i choose Test -> create new test -> wizard Then it asked me to enter a proj name. i did. then it told me to select a source proj to test, i chose my working proj... but... a warning dialog popped up saying : "Unknown virtual address 0" and refuse to continue. i tried rebuilding my source proj many times... no luc...

Conditional Inclusion/Exclusion of Data Members Inside Class Templates

I want to optimize my Vector and Matrix classes (which are class templates to be exact) using SIMD instructions and compiler intrinsics. I only want to optimize for the case where the element type is "float". Using SIMD instructions requires touching the data members. Since I don't want to be bothered with the trouble of maintaining two ...

In what scenarios should one declare a member function a friend?

In what kind of scenarios would we declare a member function as a 'friend function' ?..What exact purpose does 'friend function' which defies one of central concept of 'Encapsulation' of OOP serve? ...

Infile Handle in C++ (ala __DATA__ in Perl)

Hi, Does C++ have access to infile data through a filehandle? For example the typical idiom in Perl is: while (<DATA>) { chomp; # do sth with $_ } __DATA__ Foo Bar What's the way to do that in C++ ? ...

Problem transmitting null character over sockets

I am writing a small Java server, and a matching client in C++, which implement a simple IM service over the STOMP protocol. The protocol specifies that every frame (message that passes between server and client, if you will) must end with a null character, which in code I refer to as '\0', both in Java and in C++. However, when I tran...

Reading a Matrix txt file and storing as an array

Greetings everyone, new to the forums :) I'm currently writing a Simulated Annealing code to solve a traveling salesman problem and have run into difficulties with storing and using my read data from a txt file. Each row & column in the file represents each city, with the distance between two different cities stored as a 15 x 15 matrix:...

Howto create software package in Unix/Linux

Hi all, How can we create a software package. So that after extracting our software tar ball user can do the typical steps: $ gunzip < mycode.tar.gz | tar xvf - $ ./configure $ make $ make install ...

Python C-API Object Allocation‏

I want to use the new and delete operators for creating and destroying my objects. The problem is python seems to break it into several stages. tp_new, tp_init and tp_alloc for creation and tp_del, tp_free and tp_dealloc for destruction. However c++ just has new which allocates and fully constructs the object and delete which destructs ...

When to use reinterpret_cast?

I am little confused with the applicability of reinterpret_cast vs static_cast. From what I have read the general rules are to use static cast when the types can be interpreted at compile time hence the word static. This is the cast the C++ compiler uses internally for implicit casts also. reinterpret_cast are applicable in two scenario...

C++ include header path change windows to linux

Hi, I am porting a application written in c++ from windows to Linux. I have a problem with the header files path. Windows uses "\" and while Linux uses "/" . I am finding it cumbersome to change this in each and every source and header file. Is there some work around? ...

Playing transparent video over screen with custom user input handling

I need to play animated characters over the screen on Windows. Basically, it will be character video with transparency and only non-transparent parts should be able to accept user input (e.g. mouse clicks), all other events should be passed through to underlying window. I've made a simple transparent DirectX window with video in it. But...

[OSX .app] How to reference Resources folder in code

I'm porting a c++ Qt application from Windows to OSX and cannot wrap my head around the .app bundle concept. I hope someone can help me understand. My executable lives here: MyProgram.app/Content/MacOS/MyProgram.exe My resource folder lives here: MyProgram.app/Content/Resources/ In my code I use a relative path to reference items in t...

Excel automation. How to copy more than one cell?

For instance: //omitted vector<_bstr_t> cellData; Excel::_WorksheetPtr pSheet = application->ActiveSheet; Excel::RangePtr pRange = application->Cells; _bstr_t cellValue = pRange->Item[1][1]; //single cell cellData.push_back(cellValue); //omitted Without: MFC ATL Question: How to copy, multiple cells, for instance A1:B1, ...

How can I redirect stdout to some visible display in a Windows Application?

I have access to a third party library that does "good stuff." It issues status and progress messages to stdout. In a Console application I can see these messages just fine. In a Windows application they just go to the bit bucket. Is there a fairly simple way to redirect stdout and stderr to a text control or other visible place. Id...

C++ Vector

Look this code(and forgive the miss of knowlegde).It outputs errors that I couldnot solve.I need to declare a vector of elements of struct C,but I need the number of elements be i(a input of type int).I also tried others aproachs but in all of them I recieved an error(cannot convert C to int,etc).How can I do this? # include < iostream...