c++

problem with different linux distribution with c++ executable

Hi. I have a c++ code that runs perfect on my linux machine (Ubuntu Karmic). When I try to run it on another version, I have all sort of shared libraries missing. Is there any way to merge all shared libraries into single executable? Edit: I think I've asked the wrong question. I should have ask for a way to static-link my executable w...

[C++] Changing Function Access Mode in Derived Class

Consider the following snippet: struct Base { virtual ~Base() {} virtual void Foo() const = 0; // Public }; class Child : public Base { virtual void Foo() const {} // Private }; int main() { Child child; child.Foo(); // Won't work. Foo is private in this context. static_cast<Base&> (child).Foo(); // Okay. Foo is public ...

Opinions on not using prototypes for static functions.

Does anyone have any opinions on not using prototypes unless necessary for functions declared "static". Do you always put them at the top of your translation unit? I tend to but recently I've been thinking about why not rely on the ordering of the functions and in way you can limit some scope of where the function can be called from, pot...

How to create a program which is working similar like RAID1 (mirroring)?

Hi! I want to create a simple program which is working very similar to RAID1. It should work like this: First i want to give the primary HDD-s drive letter and than the secondary one. I will only write to the primary HDD! If any new data is copied to the primary HDD it should automatically copy it to the secondary one. I need some help ...

STL priority_queue copies comparator class

I'm trying to create a priority queue with a custom comparator: std::priority_queue<int, std::vector<int>, MyComparator> pq; My problem is that MyComparator has a method that stores additional state. Because MyComparator is copied to the priority queue (as far as I can tell), there's no way for me to call this method on the MyComparat...

Boost regexp - null-termination of search results

boost::regex re; re = "(\\d+)"; boost::cmatch matches; if (boost::regex_search("hello 123 world", matches, re)) { printf("Found %s\n", matches[1]); } Result: "Found 123 world". I just wanted the "123". Is this some problem with null-termination, or just misunderstanding how regex_search works? ...

Can you cache a virtual function lookup in C++?

Say I have a virtual function call foo() on an abstract base class pointer, mypointer->foo(). When my app starts up, based on the contents of a file, it chooses to instantiate a particular concrete class and assigns mypointer to that instance. For the rest of the app's life, mypointer will always point to objects of that concrete type. I...

How do I make a c++ project in VS2008 reference the include directory from VS2005?

I have a c++ and a c# project in Visual Studio 2008. The c++ project uses an API that was built in VS2005. I need that c++ project to reference the standard library files from VS2005. The order that the compiler searches the include directories keeps pointing to the include files from VS2008, specifically the vector file. It crashes ...

Overloading Operators in C++, exporting and Importing then in VB.NET

Howdy all, I have a weird situation. I have a C++ code that overloads the +,-,* operators and exports them in a .DLL file. Now, I want to import those overloaded operators from within VB.NET code. So it should be like this: <DllImport("StructDLL.dll")> Public Shared Function Operator +(ByVal a1 As A, ByVal a2 As A) As A End Function ...

What does ifstream::rdbuf() actually do?

I have the following code and it works pretty good (other than the fact that it's pretty slow, but I don't care much about that). It doesn't seem intuitive that this would write the entire contents of the infile to the outfile. // Returns 1 if failed and 0 if successful int WriteFileContentsToNewFile(string inFilename, string outFilenam...

How to set a value in windows registry? (C++)

I want to edit key "HKEY_LOCAL_MACHINE\Software\company name\game name\settings\value" to "1" (DWORD) This is my code: HKEY hkey; DWORD dwDisposition; if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\company name\\game name\\settings"), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition) == ERROR_SUCCESS){ DWORD dwType, dwSize; dwTy...

How do I convert a "pointer to const TCHAR" to a "std::string"?

I have a class which returns a typed pointer to a "const TCHAR". I need to convert it to a std::string but I have not found a way to make this happen. Can anyone provide some insight on how to convert it? ...

C++ algorithm for N! orderings

I have a list of N items and I am wondering how I can loop through the list to get every combination. There are no doubles, so I need to get all N! orderings. Extra memory is no problem, I'm trying to think of the simplest algorithm but I'm having trouble. ...

g++ compiler: optimization flag adds warning message

I noticed this interesting behaviour of the g++ compiler, if I add a -O3 flag to the compiler, I get otsu.cpp:220: warning: ‘x’ may be used uninitialized in this function However, when I do not use optimization and instead use a debug flag -g I got no warnings at all. Now, I trust the compiler more when the -g flag is on; however, I'm...

Good book for Monte Carlo methods in c++?

Hi! Can anybody recommend a good introduction book on Monte Carlo algorithms in c++? Preferably with applications to physics, and even more preferably, the kind of physics being quantum mechanics. Thanks! ...

Using pointer to base class as array parameter

Hey, I have 2 classes: class Base { public: virtual int Foo(int n); virtual void Goo() = 0; virtual ~Base() ; }; class Derived : public Base { public: int Add4Bytes; void Goo(); int Foo(int n); }; int Test(Base* b) { for (int i=0;i<5;++i) { b->Foo(i); ++b; } re...

friend function in derived class with private inheritance

Hi, If a class Derived is inherited privately from a class Base and the Derived class has a friend function f(), so what members can f() access from Derived class and Base class. class Base { public: int a; protected: int b; private: int c; }; class Derived: private Base { void friend f() {} public: int d; ...

QT slot get Signaled twice

In QT4.5, I use a QTableWidget, and I have connected the signal QTableWidget::itemClicked() to a custom slot like this: connect(_table, SIGNAL(itemClicked(QTableWidgetItem*)), item, SLOT(sloItemClicked(QTableWidgetItem*))); I create such a connection for each row I add to the table. The problem is that the slot sloItemClicked get ca...

C++ specific patterns due to language design.

It took me a long time to realize how important and subtle having variables that: 1) exist on the stack 2) have their destructors called when they fall out of scope are. These two things allow things like: A) RAII B) refcounted GC Interesting enough, (1) & (2) are not available in "lower" languages like C/Assembly; nor in "higher"...

Using C#/C++, is it possible to limit network traffic?

I'm developing a parental monitoring/tracking application that has a feature to lock down all internet activity. While disabling the network adapter would seem like a simple solution, the application must have the ability to turn the internet back on remotely -- so the network needs to remain enabled, to a certain limit. Unfortunately,...