c++

Basic C++ Header File Question

Hi, I have a project with two header files mainwindow.h and website.h. I want to access a method from website.cpp from inside mainwindow.cpp. I can access any function from inside mainwindow by doing Window w then doing w->function(); However, when the function finishes from inside the mainwindow the memory for w is erased. How do...

Check if file data is binary

when I write a number to binary file, it won't display. but in case of a character, it does. why? how would you check to see if the file containing character is binary? ...

Qt grabWindow coordinates shifted from GetCursorPos and GetWindowRect

In Qt, when I use the QPixmap::grabWindow(hwnd,x,y,h,w) function, the coordinates are shifted slightly, when compared to the coordinates using the windows api functions GetCursorPos and GetWindowRect. i.e. (0,0) from the point of view of GetCursorPos and GetWindowRect is at the very top left of the toolbar at the top of the window. But...

How to shrink-to-fit an std::vector in a memory-efficient way?

I would like to 'shrink-to-fit' an std::vector, to reduce its capacity to its exact size, so that additional memory is freed. The standard trick seems to be the one described here: template< typename T, class Allocator > void shrink_capacity(std::vector<T,Allocator>& v) { std::vector<T,Allocator>(v.begin(),v.end()).swap(v); } The w...

Is it a good idea to index an STL map with a pair?

Hi Everyone, I'm just wondering if it is a good idea to make a data structure like std::map< std::pair<int,int>,std::string > Just wondering how the pairs would be ordered internally... :S Thanks! ...

STL Static-Const Member Definitions

How does the following work? #include <limits> int main() { const int* const foo = &std::numeric_limits<int> ::digits; } I was under the impression that in order to take an address of a static const-ant member we had to physically define it in some translation unit in order to please the linker. That said, after looking at the prep...

What should my teacher talk about in my Advanced C++ class? [advice needed]

My teacher for Advanced C++ has opened the class up for students to suggest whatever topics we want. What are some good advanced C++ topics to know? We've already covered: template metaprogramming the STL (obviously) introduction to the boost libraries Please give reasons for suggestions as well. ...

Improving I/O performance in C++ programs[external merge sort]

I am currently working on a project involving external merge-sort using replacement-selection and k-way merge. I have implemented the project in C++[runs on linux]. Its very simple and right now deals with only fixed sized records. For reading & writing I use (i/o)fstream classes. After executing the program for few iterations, I notic...

Assign C++ instance method to a global-function-pointer ?

Greetings, My project structure is as follows: \- base (C static library) callbacks.h callbacks.c paint_node.c . . * libBase.a \-app (C++ application) main.cpp In C library 'base' , I have declared global-function-pointer as: in singleheader file callbacks.h #ifndef CALLBACKS_H_ #define CALLBA...

Set Carret position in Text Field (Win32API)

I'v created a text box and when it gets focus it sets the caret position to 0 rather than the end. I want to set it to the end. Thanks |Text Here -> Text Here| ...

operator << overload

//using namespace std; using std::ifstream; using std::ofstream; using std::cout; class Dog { friend ostream& operator<< (ostream&, const Dog&); public: char* name; char* breed; char* gender; Dog(); ~Dog(); }; im trying to overload the << operator. I'm also trying to practice good...

Creating a QLineEdit search field for items displayed in a QListView

I want to create a search field that filters the items shown in a QListView. Basically the user could type in "foo" and only items with "foo" in the DisplayRole are shown. I already have a few ideas on how to do this, but thought I'd ask those more experienced than I. My idea would be to use some signals and slots to set a filter in t...

Why do people use Command-line instead of IDE?

Hi I am learning C++ and at the very beginning used a Command-line... then I started using Xcode (and since then couldn't switch back to command line) and was just wondering some specific reasons/situations to use Command-line instead of IDE... ...

Help understanding some OpenGL stuff

I am working with some code to create a triangle that moves with arrow keys. I want to create a second object that moves independently. This is where I am having trouble, I have created the second actor, but cannot get it to move. There is too much code to post it all so I will just post a little and see if anyone can help at all. ogl_t...

Why am I not getting correct result when I calculate exponent with ^ in C++?

I am using Bode's formuala to calculate distance of nth planet from sun dist = (4 + 3*(2^(n-2)))/10 If I calculate the distance this way, I get the right values: dist[2] = ((4 + 3*1)/10.0) ; dist[3] = ((4 + 3*2)/10.0) ; dist[4] = ((4 + 3*4)/10.0) ; But doing it this way, gives me incorrect values: vector <double> dist(5); f...

How to reduce redundant code when adding new c++0x rvalue reference operator overloads

I am adding new operator overloads to take advantage of c++0x rvalue references, and I feel like I'm producing a lot of redundant code. I have a class, tree, that holds a tree of algebraic operations on double values. Here is an example use case: tree x = 1.23; tree y = 8.19; tree z = (x + y)/67.31 - 3.15*y; ... std::cout << z; // prin...

What kind of .lib file begins with "!<arch>" ?

Hi all, I have a .lib file, just wondering what compiler it's from: it begins with "!<arch>" ? Thanks ...

Inject runtime exception to pthread sometime fails. How to fix that?

I try to inject the exception to thread using signals, but some times the exception is not get caught. For example the following code: void _sigthrow(int sig) { throw runtime_error(strsignal(sig)); } struct sigaction sigthrow = {{&_sigthrow}}; void* thread1(void*) { sigaction(SIGINT,&sigthrow,NULL); try { while(...

How can I open my application by default, if I click a URL through Browser in Symbian OS 5th ed

I want to open/start my application when a I click on a particular URL from the browser for Symbian OS Series60 5th edition.(So, if I click on a "station" Url, it will start my application & play through my player) Any possible way that I can get it to do this? ...

Why is visual studio not aware that an integer's value is changing? (debugging)

I have a few simple lines of code (below). [bp] indicates a breakpoint. for(int i=0;i<300;i++){} int i=0; cout<<i; [bp] for (i=0;i<200;i++){} When I debug this in visual studio, it tells me that i is equal to 300 on the breakpoint. Annoyingly, 0 is printed to the console. Is there any way to make it realize that two var...