c++

Removing Unused (Unreferenced) Static Global Variable Constants in C++

Update, I tried removing the static modifier, and I tried putting them in a namespace (as well as both of those), and none worked. Hi, I have a header file with common constants like names and stuff that are automatically included in each project (an example follows). The thing is that they are included in the compiled binary (EXE) wh...

Best C++ development environment in Linux

I have some experience with Eclipse and Qt creator and am somewhat disappointed in their debuggers, less so in their editors. On Windows, I like Visual Studio for debugging and SlickEdit for editing (SE is also available on Linux). Is there an IDE that is somehow better than the two mentioned? ...

Does dynamic biding only happen with object on heap in C++?

Will dynamic binding happen with the object on stack? For example f() is a virtual function in both Base and Derived int main(){ Derived d1; Based *b= new Derived(); d1.f(); b->f(); } ...

C++ boost thread reusing threads

hi. I am trying to accomplish something like this: thread t; // create/initialize thread t.launch(); // launch thread. t.wait(); // wait t.launch(); // relaunch the same thread How to go about implementing something like this using boost threads? in essence, I need persistent relaunch-able thread. I would like to avoid work queue, a...

How does virtual inheritance solve the diamond problem?

class A { public: void eat(){ cout<<"A";} }; class B: virtual public A { public: void eat(){ cout<<"B";} }; class C: virtual public A { public: void eat(){ cout<<"C";} }; class D: public B,C { public: void eat(){ cout<<"D";} }; int main(){ A *a = new D(); a->eat(); } I understand the dia...

C++ problem with string stream istringstream

I am reading a file in the following format 1001 16000 300 12.50 2002 24000 360 10.50 3003 30000 300 9.50 where the items are: loan id, principal, months, interest rate. I'm not sure what it is that I am doing wrong with my input string stream, but I am not reading the values correctly because only the ...

How to inherit methods from a parent class in C++

When inheriting classes in C++ I understand members are inherited. But how does one inherit the methods as well? For example, in the below code, I'd like the method "getValues" to be accessible not through just CPoly, but also by any class that inherits it. So one can call "getValues" on CRect directly. class CPoly { private: in...

Finding minimum value in a Map

I have a map and I want to find the minimum value (right hand side) in the map. Right now here is how I did it bool compare(std::pair<std::string ,int> i, pair<std::string, int> j) { return i.second < j.second; } //////////////////////////////////////////////////// std::map<std::string, int> mymap; mymap["key1"] = 50; mymap["key2"] =...

What problems might arise when sharing an int between two threads?

Two threads accesses a shared int, x. What problems can arise from instruction reordering etc. Thread 1: x = 1; Thread 2: obj.f(x); What would change if x is declarared volatile? What would change if Thread 1 and Thread 2 runs on different cores? ...

C++ return object

I have a class that has a vector of objects. What do I need to do to return one of this objects and change it outside the class, keeping the changings? Is it possible to do with regular pointers? Is there a standard procedure? (And yes, my background is in Java.) ...

Internal class and access to external members.

I always thought that internal class has access to all data in its external class but having code: template<class T> class Vector { template<class T> friend std::ostream& operator<<(std::ostream& out, const Vector<T>& obj); private: T** myData_; std::size_t myIndex_; std::size_t mySize_; public: Vector():myData_(nullptr), myInd...

How to get source code of a Windows executable?

I've got some old Windows executable files. How can I edit them with Visual Studio 2010? What are the ways to see an exe's source code? ...

C++: Unitialized variables garbage

int myInt; cout << myInt; // Garbage like 429948, etc If I output and/or work with unitialized variables in C++, what are their assumed values? Actual values in the memory from the "last user"? e.g.: Program A is closed, it had an int with the value 1234 at 0x1234 -> I run my program, myInt gets the address 0x1234, I output it like...

how to clear XFixes regions

Hi, I'm writing some low level code for X11 platform. To achieve best data copying performance I use XFixes/XDamage extensions. How can I clear the contents of XFixes region after one refresh cycle? Or do they clean themselves after I use XFixesSetPictureClipRegion? My code is something like that: Display xdpy; XShamPixmap pixmap_; ...

How does sizeof calculate the size of structures

I know that a char and an int are calculated as being 8 bytes on 32 bit architectures due to alignment, but I recently came across a situation where a structure with 3 shorts was reported as being 6 bytes by the sizeof operator. Code is as follows: #include <iostream> using namespace std ; struct IntAndChar { int a ; unsigned c...

How can I get the Python module and line number that called my C++ function via Boost::Python?

I have a C++ function that is being called from many Python functions via Boost::Python. When the C++ function detects bad arguments I want to write a log message and continue processing. In that log message I would like to note the Python module and line number that called into C++. How can I do this? I am able to throw an exception fr...

C++ Converting image to integer array

How would I go about converting the pixels in an image (.png file) to an integer array, where each pixel is converted to its ARGB integer equivalent? Not a 2D integer array by the way, a 1D one (where access is through array[row*width+col]). Thanks. ...

Qt double click check left button mouse

I need to run slot only on doubleClick with left button mouse, instead of both. connect(this -> myComponent, SIGNAL (doubleClicked (const QModelIndex & )), this, SLOT (performSomeAction(const QModelIndex & ))); With this event, double click works in both cases, but needed only with left button click. How I can do it? this -> myComp...

How to determine magnitude of trigonometric function? C++

> if (((test>=0) && (test<=90)) || ((test>270) && (test<=360))){n_y=1;} > else {n_y=-1;} I need the magnitude of trigonometric function in order to determine the sign of the trigonometric function for an angle falling into a particular quadrant. My plan is to replace the code above with something equivalent. Here is what I w...

How to press the keys on keyboard without using keyboard?

I want my program to press certain keys on my keyboard without me doing it physically. How i do this? Edit: found this keybd_event() function. seem to be working http://www.codeproject.com/KB/cpp/sendkeys_cpp_Article.aspx ...