c++

How to sort std::list<..>

Hi, i have a list of Elemtents of a custom type: std::list<CDataTransferElement*> m_list; The class is defined like this: class CDataTransferElement { public: CDataTransferElement(void); ~CDataTransferElement(void); CString Name; double PercentValue; double MOLValue; int PhaseIndex; }; I have x Items ...

How to make a less than comparison in template meta-programming?

I had this question asked of me on Monday and for the life of me I don't know how to answer. Since I don't know, I now want to very much find out. Curiosity is killing this cat. Given two integers, return the lesser at compile time. template<int M, int N> struct SmallerOfMandN{ //and magic happenes here }; Got pointers or how t...

C++ Copy through assignment problem

Howdy, I seem to be having trouble with the following function: void OtherClass::copy_this( int index, MyClass &class_obj) { if(index < MAX_index) class_obj = array_of_MyClass[index]; } OtherClass maintains an array of MyClass objects, and I would like this function to copy a selected object out of the array into the prov...

How do I use the latest OpenGL ?

Hi, quite new to the subject, and in college we were provided with the .dlls each time we needed them. But I never had any idea what actual version I was using, what extensions I was using...This is very confusing to be honest. I couldn't find any download link on the official khronos site. Clicking on the OpenGL SDK link, just presents ...

Qt - draw in a QFrame on clicking a button.

Say there is a QPushButton named "Draw", a QLineEdit and a QFrame. On clicking the button I want to take a number from QLineEdit and draw a circle in a QFrame. How can I do this? Please provide me with the code. P.S. The problem is that draw methods of the QPainter should be called in drawEvent method. ...

Slicing problem?

g++ -std=gnu++0x main.cpp In file included from main.cpp:6:0: CustArray.h: In constructor 'CustArray::CustArray()': CustArray.h:26:32: error: 'class Info' has no member named 'someInfo' make: *** [all] Error 1 /* * Info.h * */ #ifndef INFO_H_ #define INFO_H_ class Info { friend class CustArray; }; #endif /* INFO_H_ */ /* * ...

Does growing files on Linux cost anything?

Is there any noticeable difference in speed between these 2 scenarios? Scenario 1: I have a file of size 1024 bytes filled with 0s for every byte. I open the file and write 1024 bytes of 1s with fwrite. Scenario 2: I have a file of size 512 bytes filled with 0s for every byte. I open the file and write 1024 bytes of 1s with fwrite. Ob...

resolve function does't work in boost/asio

I am learning boost/asio and writing example program which was in e-book. of course it didn't work ;) #include <boost/asio.hpp> #include <iostream> int main () { boost::asio::io_service io_service; boost::asio::ip::tcp::resolver::query query("www.boost.org", "http"); boost::asio::ip::tcp::resolver::iterator destination = boost...

return statement in lambda expression

Hi All I created a lambda expression inside my std::for_each call. In it there is code like this one, but I have building error telling me that error: expected primary-expression before ‘return’ error: expected `]' before ‘return’ In my head I think that boost-lambda works mainly with functors, so since return statement it isn't li...

How many characters does string class in c++ support ?

Possible Duplicate: Maximum length of a std::basic_string<_CharT> string I would like to know how many characters does string class in c++ support. thanks.. ...

Null check on a COleVariant

Is it possible to do a null check on a COleVariant or at the very least check if it's type is set to VT_NULL? I see that there is a ChangeType() method but was hoping I could somehow figure out what the current type was before I attempt to change the type as changing from VT_NULL to VT_INT throws a type mismatch. ...

difference between "long" and "long int", abs & labs

This is probably just an inconsistency of notation at cplusplus.com, but is there a difference between "long int" and "long" types in C++? cplusplus.com says that abs takes inputs of types "int" and "long", whereas labs uses "long int". I assume that this is basically a typo. If so, then is the only difference between abs and labs tha...

Mutex protection for Singleton resources in multithreaded env

I have a server listening on a port for request. When the request comes in, it is dispatched to a singleton class Singleton. This Singleton class has a data structure RootData. class Singleton { void process(); void refresh(); private: RootData mRootData; } In the class there are two functions: process: Work with the mRo...

QuickTime component with Xcode 3.2: C++ compilation errors

I'm trying to compile the Xiph QuickTime component Xcode project on OS X. It depends on a number of libraries such as libflac and Theora; all of those dependencies appear to be C code which all compiles nicely with the 10.5 SDK. However, when it comes to compiling the component itself, I get a number of errors, mostly along the lines of ...

how to bind one function to other

I have a function A that accepts a predicate function as its argument. I have another function B and it takes a char and returns an int, and a function C that accepts int and returns a bool. My question is how to bind B and C to pass it to function A. Something like: A(bindfunc(B,C)) I know boost::bind works but i am looking for ...

shared_ptr by reference or by value?

When a function should take a boost::shared_ptr, are you passing it by const reference void foo(const boost::shared_ptr<T>& p) or by value void foo(boost::shared_ptr<T> p) ? I would prefer the first method because I suspect it to be faster. But is this really worth a though or are there any additional issues? Edit: Could you please g...

no matching function for call to ‘Gtk::Main::run(window (&)())

I guess I'm not understanding something about C++: I have this code: #include "window.h" int main(int argc, char* argv[]) { Gtk::Main kit(argc, argv); window win(); Gtk::Main::run(win); return EXIT_SUCCESS; } 'window' is a class that inherits from Gtk::Window with an empty constructor. When I try to compile this co...

problem writing a simple STL generic function

I'm self-learning how to create generic functions using iterators. As the Hello World step, I wrote a function to take the mean in the given range and returns the value: // It is the iterator to access the data, T is the type of the data. template <class It, class T> T mean( It begin, It end ) { if ( begin == end ) { throw...

Graphical artifacts with OpenGL?

I'm not sure if its called a graphical artifact but see this: http://img835.imageshack.us/img835/9785/anomoly.png You will notice 6 pixels on the black outline that are out of place. My application allows zooming in and when I render I do this: RENDER: // Set an orthogonal projection matrix glMatrixMode(GL_PROJECTION); glLoad...

Method resolution order in C++

Consider the following class hierarchy: base class Object with a virtual method foo() an arbitrary hierarchy with multiple inheritance (virtual and non-virtual); each class is a subtype of Object; some of them override foo(), some don't a class X from this hierarchy, not overriding foo() How to determine which method will be executed...