c++

C++ vectors question

Hello! Does anyone know how to speed up boost::numeric::ublas::vector? I am using typedef ublas::vector<float, ublas::bounded_array<float, 3> > MYVECTOR3 and compare it's speed to D3DXVECTOR3 on plain operations. The test look the following way: #include <d3dx9.h> #pragma comment(lib, "d3dx9.lib") static const size_t kRuns = static_...

Behavior of STL remove() function - only rearrange container elements?

I've read here on StackOveflow and other sources that the behavior of the remove function is simply re-ordering the original container so that the elements that are TO BE REMOVED are moved to the end of the container and ARE NOT deleted. They remain part of the container and the remove() function simply returns an iterator that delimits...

Iterate forward and then reverse over STL container

I have an STL container and I need to perform an action on each element in the container. But if the action fails on any element, I want to reverse the action on any elements that have already been changed. For example, if I had an STL vector with pointers to a number bankAccount classes and wanted to increase each one by $50. But i...

Qt Creator problem. UI changes not showing when project is built.

I'm making changes to a form in Creator but when I build the changes are not being "refreshed". I've gone so far as to remove every element from the form and get rid of every stylesheet but when I build the project I get the same result; as if I had never made a change at all. What gives? Am I missing something obvious? (obvious to every...

What is an idiomatic way to determine pointer limits in C++?

I'd like to know at compile-time the range of values for a pointer type. limits.h only specifies maximums and minimums for pure number types. I don't wish to use hard-coded constants, and I prefer not to compute a max using sizeof(foo*). ...

Can I read a dynamical length variable using fread without pointers?

I am using the cstdio (stdio.h) to read and write data from binary files. I have to use this library due to legacy code and it must be cross-platform compatible with Windows and Linux. I have a FILE* basefile_ which I use to read in the variables configLabelLength and configLabel, where configLabelLength tells me how much memory to alloc...

Cross Compiler Binary Execute Error

I just built a cross compiler using crosstools "mips-unknown-linux-gnu-gcc" and I compiled a hello world program. The compilation went fine using the command: "mips-unknown-linux-gnu-g++ hello.cpp -o hello" but when I run the command "./hello" I get the following error: babbage-dasnyder 50% mips-unknown-linux-gnu-g++ hello.cpp -o hello...

C++ CppUnitTest (CPPUNIT_ASSERT_EQUAL)

I'm trying to do some CppUnit testing on my program using Ubuntu NetBeans but I keep encountering similar errors (invalid use of void expression). I'm not sure what went wrong. Any help will be greatly appreciated. The error goes like this: g++ -c -O2 -I/usr/include/cppunit -MMD -MP -MF build/Release/GNU-Linux-x86/AssignmentTest.o.d...

WinAPI I/O Redirection - Read as Information is Available using Anon Pipes & Threads

I am creating an application which will read the output from another application (which I did not write) which sends its output to a command prompt. I need to be able to write this information an "Edit" dialog within my GUI program. I have accomplished this using anonymous pipes and multi-threading (a worker thread for writing and anothe...

Cannot convert 'this' pointer to Class&

Can someone tell why i'm getting this error when compling this class? class C { public: void func(const C &obj) { //body } private: int x; }; void func2(const C &obj) { obj.func(obj); } int main() { /*no code here yet*/} ...

std::tr1::function and std::tr1::bind

I have a problem using a very complicated C function in a C++ class (rewriting the C function is not an option). C function: typedef void (*integrand) (unsigned ndim, const double* x, void* fdata, unsigned fdim, double* fval); // This one: int adapt_integrate(unsigned fdim, integrand f, void* fdata, ...

Using Qt signals and slots with multiple inheritance

I have a class (MyClass) that inherits most of its functionality from a Qt built-in object (QGraphicsTextItem). QGraphicsTextItem inherits indirectly from QObject. MyClass also implements an interface, MyInterface. class MyClass : public QGraphicsTextItem, public MyInterface I need to be able to use connect and disconnect on MyInterfa...

How do I use a priority queue in c++?

For example we have priority_queue<int> s; which contains some elements. What will be correct form of the following code: while (!s.empty()) { int t=s.pop();// this does not retrieve the value from the queue cout<<t<<endl; } ...

c++: set<customClasS* how to overload operator<(const customClass&*...)?!

Good Evening (depending on where u are right now). I am a little confused with the stl stuff for sorted sets... I want to store pointers of a custom class in my set and I want them to be sorted by my own criterion and not just the pointer size. Anyone has an idea how to do this? Since it is impossible to do it like operator<(const foo ...

How to eliminate the '\n' at the end of a txt file.

Hi guys I'd like to eliminate the extra '\n' at the end of a txt file. Which function can be used to do this job in c / c++. Thanks advanced ...

String Selection Sort C++

How would I modify a selectionSort function to search an array of strings? void selectionSort (int array[], int size) { int startScan, min Index, minValue; for (startScan = 0; startScan<(size-1); startScan++) { minIndex=startScan; minValue=array[startScan]; for(int index = startScan + 1;index<size;ind...

Clearing Contents of a File in C++ knowing only the FILE *

Is it possible to clear the contents (ie. set EOF to the beginning/reset the file) in C++ knowing just the FILE*? I'm writing to a temp file with wb+ access and wish to sometimes clear it and truncate it without adding the calls to fclose and fopen. I dont think it's possible... but if not, why not? Thanks in advance! ...

What every c++ programmer need to know about 'this' pointer?

Hi, straight and clear as the title says :) Background: I run into some tutorial and I realized that I missed some things... So, I would really appreciate if anyone can point out any must_know_facts with an example. Thanks! ...

How to handle a float overflow?

If a float overflow occurs on a value, I want to set it to zero, like this... m_speed += val; if ( m_speed > numeric_limits<float>::max()) { // This might not even work, since some impls will wraparound after previous line m_speed = 0.f } but once val has been added to m_speed, the overflow has already occurred (and I'm assuming tha...

Calling command prompt from Qt application without freezing?

Hello, In my Qt GUI application, I am calling the command prompt through: system("lots.exe & of.exe && commands.exe"); It opens up the command prompt (like I want it to), but freezes the Qt GUI application until I close the command prompt. Is there someway to prevent this? I saw that there is a QProcess class, but can't get it to br...