c++

How does py2exe actually -and simply explained- work? :)

Hi folks, I have a c++ app that calls another python one (bundled into an exe with py2exe) So I have 2 apps. So I was wondering: What if my c++ did what py2exe does? i.e. embed the python app in the c++ one. This way I won't depend on py2exe and its configurations nighmares (yes, it has some) Hence my questions: how does py2ex...

How to discard const in c++

This is what I'm trying to do and I can't: #include <string> using namespace std; class A { public: bool has() const { return get().length(); } string& get() { /* huge code here */ return s; } private: string s; }; The error I'm getting is: passing ‘const A’ as ‘this’ argument of ‘std::string& A::get()’ discards qualifiers I ...

How should I compile boost library in a small project?

I have a small project where I need just part of boost library, boost::regex in particular. This is what I've done so far: /include /boost /regex /math .. 189 dirs, files, etc. /lib /boost-regex c_regex_traits.cpp cpp_regex_traits.cpp .. ~20 .cpp files myprog.cpp In my Makefile I compile all boost-regex .cp...

Read file-contents into a string in C++

In scripting languages like Perl, it is possible to read a file into a variable in one shot. open(FILEHANDLE,$file); $content=<FILEHANDLE>; What would be the most efficient way to do this in C++? ...

Generating XML Documents from XML Schemas in C++

Is there any easy way to create at least a template XML file using XML Schema? My main interest is bounded by C++, but discussions of other programming languages are also welcome.By the way I also use QT framework. ...

C++0x: memory ordering

The current C++0x draft states on section 29.3.9 and 29.3.10, pages 1111-1112 that in the following example: // Thread 1 r1 = y.load(memory_order_relaxed); x.store(1, memory_order_relaxed); // Thread 2 r2 = x.load(memory_order_relaxed); y.store(1, memory_order_relaxed); The outcome r1 = r2 = 1 is possible since the operations of each...

SysRc enum values in c c++

i am working on a project where i am using SysRc values as return values from some function like SUCCESS and FAILURE ond sum enums . Now i want to know how to get them print? ...

How to design properly a hierarchy of classes using pointers in C++

Hello, I am trying to improve my knowledge on program architecture and recently arised a question to me which is related with this pointers issues I posted recently. The thing is that in a simple hierarchy in which you have Class A with a pointers to Class B and the last to Class C. Do not confuse the with the inheritage property of th...

c++ - Is it possible to cast object of class to void * ?

I am trying to use qsort from STL to sort array of edge: struct edge { int w,v,weight; }; by weight. What I am trying is: int compare_e(const void *a, const void *b) { return ( *(edge *)a->weight - *(edge *)b->weight ); }; But I get: `const void*' is not a pointer-to-object type EDIT: Ok thx, now my code is compil...

c++ inheritance

Hi, i am trouble with this.. Is there some solution or i have to keep exactly class types? //header file Class Car { public: Car(); virtual ~Car(); }; class Bmw:Car { public: Bmw(); virtual ~Bmw(); }; void Start(Car& mycar) {}; //cpp file Car::Car(){} Car::~Car() {} Bmw::Bmw() :Car::Car(){} Bmw::~Bmw() {} int...

Even lighter than SQLite

I've been looking for a C++ SQL library implementation that is simple to hook in like SQLite, but faster and smaller. My projects are in games development and there's definitely a cutoff point between needing to pass the ACID test and wanting some extreme performance. I'm willing to move away from SQL string style queries, allowing it to...

How can I keep an event from being delivered to the GUI until my code finished running?

I installed a global mouse hook function like this: mouseEventHook = ::SetWindowsHookEx( WH_MOUSE_LL, mouseEventHookFn, thisModule, 0 ); The hook function looks like this: RESULT CALLBACK mouseEventHookFn( int code, WPARAM wParam, LPARAM lParam ) { if ( code == HC_ACTION ) { PMSLLHOOKSTRUCT mi = (PMSLLHOOKSTRUCT)lParam; ...

SHFileOperation FO_MOVE deletes a file if the destination drive is full

I had a piece of code which uses windows SHFileOperation function with FO_MOVE operation. Additional flags specified were FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT. A particular weird behavior was observed when the destination drive was full. In this case, MOVE could not place the file in destination folder but the source file was...

Execute hidden process in Windows Mobile 6

Hello everyone, I have a test.exe that need to be called in my main application and run in the background (my main app must stay on top). I know we can use CreateProcess with hide option in MFC, but in windows mobile library the startupinfo is unavailable. So does anyone have an idea how to do ? Besides, is there any way that we can l...

A follow up on type coercion in C++, as it may be construed by type conversion

This is a follow up to my previous question. Consider that I write a function with the following prototype: int a_function(Foo val); Where foo is believed to be a type defined unsigned int. This is unfortunately not verifiable for lack of documentation. So, someone comes along and uses a_function, but calls it with an unsigned int ...

Ways not to write function headers twice?

Hi, I've got a C/C++ question, can I reuse functions across different object files or projects without writing the function headers twice? (one for defining the function and one for declaring it) I don't know much about C/C++, Delphi and D. I assume that in Delphi or D, you would just write once what arguments a function takes and then...

Quicksort / vector / partition issue

Hi, I have an issue with the following code : class quicksort { private: void _sort(double_it begin, double_it end) { if ( begin == end ) { return ; } double_it it = partition(begin, end, bind2nd(less<double>(), *begin)) ; iter_swap(begin, it-1); _sort(begin, it-1); _sort(it, end); } public: quicksort (){} ...

How to get only first words from several C++ strings?

I have several C++ strings with some words. I need to get first word from every string. Then I have to put all of them into a char array. How can I do it? Thanks i advance! ...

Is C++ (one of) the best language to learn at first

C++ is one of the most used programming language in the world since like 25+ years. My first job as programmer was in C++ and I coded in C++ everyday for nearly 4 years. Now I do mostly PHP, but I will forever cherish this C++ background. C++ has helped me understand many "under the hood" features/behaviors/restrictions of many other (...

Including non-standard C headers in C++

I needed to include a few c headers ( non standard header files ) in my C++ code to be compiled by gcc. The C header (foo.h) has support for : #ifdef __cplusplus extern "C" { #endif and similarly at the end for }. The c++ code has the include "foo.h" I believe I should be able to just include the header (foo.h) and create instan...