c++

C++, workaround for macro using 'this' in static member functions

I've overridden new so that I can track memory allocations. Additional parameters such as __FILE__, __LINE__, module name etc are added in the #define. However I want to add the address of the calling object to the parameters so that I can backtrack up allocations when hunting down problems. The easiest way is to add 'this' to those add...

Template problem.

Why on earth I can do this: #include <iostream> #include <algorithm> #include <vector> using namespace std; void myfunction (int i) { cout << " " << i; } int main () { vector<int> myvector; myvector.push_back(10); myvector.push_back(20); myvector.push_back(30); cout << "myvector contains:"; for_each (myvector.begin(),...

how should to implement correctly a constructor of a class with stls inside

hey I i am writing a Program in C++ and for some reason the compiler finds errors , and cant find my constructor: here is my class: (inside a h file) class Adjutancy { private: vector<Vehicale*,CompareCatId>* m_vehicalesVector; map<const string,Base*>* m_baseMap; map<const int,City*>* m_citiesMap; vector<vector<Distance*>>* m_distan...

Can I call memcpy() and memmove() with "number of bytes" set to zero?

Do I need to treat cases when I actully have nothing to move/copy with memmove()/memcpy() as edge cases int numberOfBytes = ... if( numberOfBytes != 0 ) { memmove( dest, source, numberOfBytes ); } or should I just call the function without checking int numberOfBytes = ... memmove( dest, source, numberOfBytes ); Is the check in ...

How to get the index of a value in a vector in C++0x for_each algorithm and lambda expression?

I have the following C++0x code (compiler- MSVC++ 10): std::vector<float> data; data.push_back(1.0f); data.push_back(1.0f); data.push_back(2.0f); // lambda expression std::for_each(data.begin(), data.end(), [](int value) { // Can I get here index of the value too? }); What I want in the above code snippet is to get the index of ...

is this some kind of optimization? if (1) { ... } else (void)0

Possible Duplicate: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? In the source code of OpenJDK I found this macro: #define PUTPROP(props, key, val) \ if (1) { \ // some code } else ((void) 0) It is used as one would expect, e.g.: PUTPROP(props, "os.arch", sprops->os_arch...

STLish lower_bound function for Radix/Patricia Trie

Lately I've been studying Patricia tries, and working with a really good C++ implementation which can be used as an STL Sorted Associative Container. Patricia tries differ from normal binary trees because leaf nodes have back pointers which point back to internal nodes. Nonetheless, it's possible to traverse a Patricia trie in alphabet...

problems using a class template

i created a template that contains a map. when i try to create an instance of that template i encounter a linking problem with the constructor and destructor. also, when i try to create an instance in main it skips the line while debugging, and doesn't even show it in the locals list. it doesn't compile "DataBase db;" unless i add "()" a...

Mistake in calling std::stable_sort ?

struct SimGenRequest { int wakeup_mfm_; double value_; bool operator < ( const SimGenRequest & r2 ) const { return ( wakeup_mfm_ < r2.wakeup_mfm_ ) ; } }; Use : std::stable_sort ( all_requests_.begin ( ), all_requests_.end ( ) ); Works ( compiles ). But struct SimGenRequest { int wakeup_mfm_; doubl...

how commenting the following lines of code, can change the behviour of the previous ones?!

Hi, NOTE: I do believe that this is not an openCV related problem but since the error occurred using this library it might be a point of interest. In the following code, by giving the wrong parameter as cascade_name, the load function throws an exception which is expected. The interesting point is that by commenting the two following l...

how to define a vector with a functor

hey, i implemented the following functor: struct CompareCatId : public std::binary_function<Vehicle*, Vehicle*, bool> { bool operator()(Vehicle* x, Vehicle* y) const { if(x->GetVehicleType() > y->GetVehicleType()) return true; else if (x->GetVehicleType() == y->GetVehicleType() && x->GetLicenseNumb...

Show Windows Users Dialog

Hello Folks, How do you (programatically) show the windows local users/groups dialog? In Vista it's usually under Control Panel - Administrative Tools - Computer Management - Local Users and Groups. Similar kind of dialog with the same functionalities (add/remove users/groups) is also acceptable, as long as supported by Windows Xp and a...

QByteArray to char*, sending with libcurl

I'm having trouble with saving a QPixmap to QByteArray, then writing it to char*. For example i'm trying to write to a file with ofstream. QByteArray bytes; QBuffer buff(&bytes); buff.open(QIODevice::ReadOnly); pixmap.save(&buff, "PNG"); QString str(by...

Strong guarantee method calling strong guarantee methods

Hi all, When I have a method that calls a set of methods that offer strong guarantee, I often have a problem on rolling back changes in order to also have a strong guarantee method too. Let's use an example: // Would like this to offer strong guarantee void MacroMethod() throw(...) { int i = 0; try { for(i = 0; i < 100; ++i) ...

C++ matrix-vector multiplication

Hello! When working with 3d graphics, sample shaders USUALLY use the following operation for vector position transformation: result = mul(matrix, vector); This obviously means the same as: result = mul(vector, matrix_transposed); Also, just to mention, most linear algebra libraries prefer to only leave the vector * matrix multiplic...

How do I create a pause/wait function using QT

Hello, I'm playing around with QT and I want to create a simple pause between two commands. However it won't seem to let me use Sleep(int mili); and I can't find any obvious wait functions. I am basically just making a console app to test some class code which will later be included in a proper QT GUI, so for now I'm not bothered about...

OpenCV VideoWriter Error when using DIVX codec (vs2008, Win7, x64)

Hello, I'm trying to save a video to a file using OpenCV. But when I want to use more advanced codecs like DIVX or something I get the following error as soon as i call operator <<. For example the following snippet will bring up the error: cv::VideoWriter testwriter("C:\\test.avi", CV_FOURCC('D', 'I', 'V', 'X'), 25, cv::Size(500,500...

How to preview variables in containers (e.g. std::map> in NetBeans in C++?

As I see, it's impossible to figure out what is in an STL map using NetBeans. Is there any plugin/trick/solution that will allow me to print out all values from a map in debug mode? As far as I know it's using GDB for debugging C++ applications. I've found some nice GDB macros for STL containers (here: http://sourceware.org/ml/gdb/2008...

GCC vs MS C++ Compiler

I often read that the GCC compiler is much better than the Microsoft compiler on various forums and comment thread. This is always because "Micro$oft is evil" and that GCC is open-source. Are there any technical reasons that GCC is better? Are there any scenarios where one would want to use GCC over MS for windows development? Are there ...

How to put NULL in all cells of a matrix vector?

Hello, i'm trying to initialize all cells of a matrix with NULL values, but something is wrong here. the code : vector<vector<Distance*> > distanceMatrix; for (int i = 0; i < 7 ; i++) for (int j = 0; j < 7 ; j++) distanceMatrix[i][j].push_back(NULL); i bet it's something stupid, thanks for the help. ...