c++

Iterating over vector and calling functions

I have a class that has a vector of another class objects as a member. In many functions of this class I have to do same operation on all the objects in the vector: class Small { public: void foo(); void bar(int x); // and many more functions }; class Big { public: void foo() { for (size_t i = 0; i < V...

How does one share data between a C++app and a C# app without files?

Hello there, I have a C++ application with data that needs to be shared with a C# application. I'm currently transferring the data via files, but with speed and quantity of the data becoming an issue I would like to find a way to share the data through memory. I'm a beginner to intermediate programmer at best, and so far I have heard o...

Disadvantages of a <std.h> file that brings in all std headers?

I find long sequences of standard includes annoying: #include <vector> #include <string> #include <sstream> #include <iostream> Considering these header files change only very rarely, is there a reason why I should not make a "std.h" file #including all std headers and just use that everywhere? ...

Friend template functions (in non-template classes), C++

If I have a non-template (i.e. "normal") class and wish to have a template friend function, how do I write it without causing a compiler error? Here is an example to illustrate what I am trying to do: template <class T> void bar(T* ptr); class MyClass // note that this isn't a template class { private: void foo(); template <...

.NET marshalling speed

Hi all, I have a C++ method signature that looks like this: static extern void ImageProcessing( [MarshalAs(UnmanagedType.LPArray)]ushort[] inImage, [MarshalAs(UnmanagedType.LPArray)]ushort[] outImage, int inYSize, int inXSize); I've wrapped the function in timing methods, both internal and external. Inter...

Impersonating users to access hives - various methods, what are the practical issues?

I am designing a Service to run under LocalSystem account on Win2000, XP and Vista. It will need access to users registry hives, sometimes for extended periods of time, both when the users are logged-in, and also, when they are not logged-in (IF the profile is local. If the profile is Roaming and not loaded, I will not attempt to load it...

What is the difference: LoadUserProfile -vs- RegOpenCurrentUser

These two APIs are very similar but it is unclear what the differences are and when each should be used (Except that LoadUserProfile is specified for use with CreateProcessAsUser which I am not using. I am simply impersonating for hive accesss). LoadUserProfile http://msdn.microsoft.com/en-us/library/bb762281(VS.85).aspx RegOpenCurrent...

C++ code coverage tool running on command line

I use code coverage tool for writing unit testing cases. I have a code coverage tool but only have to do everything through its GUI interface. Ideally I'd like to get a tool that is able to produce a text output (.diff is the best) on individual .cpp files. Does such a tool exist? ...

Putting a close button on QTabWidget

I'm using a QTabWidget to render multiple documents in a window, and I want to draw a close button on each tab. I'm using Vista and Qt4, so the tab widget is a native windows control; this may affect the feasibility. Does anyone know if it is possible to do this using the QTabWidget control, or do I have to create a custom widget? If cr...

C++ metaprogramming - generating errors in code

Is there a way that I can create a function that takes an int template parameter, and have that function give a compile time error if the value passed to the function is less than 10? The following code does not work, but it shows what I want to accomplish: template <int number1> void reportErrorIfLessThan10() { #if(number1 < 10) ...

boost weak_ptr_cast in shared_from_this()

I'm using boost's shared pointers, and enable_shared_from_this to enable returning a shared pointer to this. Code looks like this: class foo : public boost::enable_shared_from_this<foo> { boost::shared_ptr<foo> get() { return shared_from_this(); } } Why would shared_from_this throw a weak_ptr_cast exception? ...

How can I avoid dynamic_cast in my C++ code?

Let's say I have the following class structure: class Car; class FooCar : public Car; class BarCar : public Car; class Engine; class FooEngine : public Engine; class BarEngine : public Engine; Let's also give a Car a handle to its Engine. A FooCar will be created with a FooEngine* and a BarCar will be created with a BarEngine*. Is ...

Can I simplify this?

typedef void (FunctionSet::* Function)(); class MyFunctionSet : public FunctionSet { protected: void addFunctions() { addFunction(Function(&MyFunctionSet::function1)); } void function1() { // Do something. } }; The addFunction method adds the function to a list in the base class, which can then be en...

C++ I/O Rereading a file after EOF (was: Parsing a Comma Delimited Text File)

Lets take a look at the code: #include <iostream> #include <fstream> #include <string> #include <cstdio> #include <cstdlib> using namespace std; int main() { string usrFileStr, fileStr = "airNames.txt", // declaring string literal sLine; // declaring a string obj fstream inFile; ...

Why would SDL_Mixer not play music for certain mp3s?

Why would SDL_Mixer not play music for certain mp3s? I am utilizing SDL_Mixer for music playback in an application I am creating. On certain songs (entire albums actually), the music will simply not play without returning any errors. The music data loads successfully using Mix_LoadMUS and when executing Mix_PlayMusic with that data, it ...

Recommendations: Easy To Use/Low Dependency C/C++ RSS Library

Just like the title says. Anyone know of an RSS reading library for C/C++? Ideally: Minimal/no outside non-standard dependencies Easy to use API Cross platform would be ideal, but I'm OK with Win* only if necessary. I'd just rather not roll my own if necessary. :) ...

window handlers for opengl

I've been programming opengl using glut as my window handler, lately i've been thinking if there are any advantages to switching to an alternate window handler such as wxWidgets or qt. Are there any major differences at all or is it just a matter of taste? Since glut provides some additional functions for opengl-programming beyond the w...

Defining class string constants in C++?

I have seen code around with these two styles , I am not not sure if one is better than another (is it just a matter of style)? Do you have any recommendations of why you would choose one over another. //Example1 class Test { private: static const char* const str; }; const char* const Test::str = "mystr"; //Example2 c...

A way to ensure that a system tray icon is removed... guaranteed

Is there a way to guarantee that your system tray icon is removed? To add the system tray icon you do: Shell_NotifyIcon(NIM_ADD, &m_tnd); To remove the system tray icon you do: Shell_NotifyIcon(NIM_DELETE, &m_tnd); What I want to know: what if you application crashes? The icon stays in your system tray until you mouse over. Is th...

C++ Forward Declaration Problem when calling Method

I have a problem which I think is related to forward declarations, but perhaps not. Here is the relevant code: A.h #ifndef A_H_ #define A_H_ #include "B.h" class A { private: B b; public: A() : b(*this) {} void bar() {} }; #endif /*A_H_*/ B.h #ifndef B_H_ #define B_H_ #include "A.h" class A; class B {...