c++

name collision in C++

Hi all, While writing some code i came across this issue: #include <iostream> class random { public: random(){ std::cout << "yay!! i am called \n" ;} }; random r1 ; int main() { std::cout << "entry!!\n" ; static random r2; std::cout << "done!!\n" ; return 0 ; } When i try to compile this code i get the error error: ârandomâ d...

Pass by value or reference, to a C++ constructor that needs to store a copy?

Should a C++ (implicit or explicit) value constructor accept its parameter(s) by value or reference-to-const, when it needs to store a copy of the argument(s) in its object either way? Here is the shortest example I can think of: struct foo { bar _b; foo(bar [const&] b) // pass by value or reference-to-const? : _b(b) { ...

Why is there a performance warning on cast pointer to bool?

Extends. I thought I was being cool when I did something like: bool hasParent() { return this->parentNode ; } Even with a (bool) cast, the warning still doesn't go away. Where this->parentNode is NULL when there is no parent node. But I'm getting: warning C4800: 'Node *' : forcing value to bool 'true' or 'false' (performance w...

What is the reason for not allowing in C++ a default value for a variable to be a non-static method or member of a class ?

I wanted to know why the default value for a variable for a method of a class, cannot be a non-static method or member of the same class. Is there a reason for that ? Could not the compiler provide to the method the position in the class of the non-static default value ? I tried to google quickly for an answer but I could not come up w...

Why does `include <iostream>` end up including so *many* files?

Follow up of this question: When I do include <iostream> . It happens that it includes many files from /usr/include .A grep "\usr\include" over g++ -E prog.cpp counted to about 1260 entries ;). Is their a way to control including various files? Platform: Linux G++ version: 4.2.4 ...

In windbg, How to set breakpoint on all functions in kernel32.dll ?

I want figure out the call sequence and functions to kernel32.dll in a function example() in example.DLL. In windbg, how to set breakpoint on all functions in kernel32.dll? I tried bm kernel32!* , but seems not work. ...

c++ destructor mess, impossible to debug...

Hello, when I run my program everything goes fine. At the end it prints out this: *** glibc detected *** ./streamShare: double free or corruption (fasttop): 0x08292130 *** ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0xcc2ff1] /lib/tls/i686/cmov/libc.so.6[0xcc46f2] /lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xcc779d] /usr/li...

What is the best way for two programs on the same machine to communicate with each other

I need to pass some data (integers) from one (C++) program to another (C#). What is the fastest way to do this? P.S.: OS: Windows XP ...

biggest integer that can be stored in a double

What is the biggest "no-floating" integer that can be stored in a double C type (IEEE) without loosing precision ? ...

c++ read from file redirection and also keyboard

My program reads a list of integers from user input [ keyboard] and calculates some statistics The user enters 'x' to terminate the input process. So for example, Enter integers separated by space ( enter x to quit) : 1 2 3 4 5 x But now I want to include the inputs to be read from file redirection also. So if the numbers followed ...

How can you detect if two regular expressions overlap in the strings they can match?

I have a container of regular expressions. I'd like to analyze them to determine if it's possible to generate a string that matches more than 1 of them. Short of writing my own regex engine with this use case in mind, is there an easy way in C++ or Python to solve this problem? ...

C++ - Arguments for Exceptions over Return Codes

I'm having a discussion about which way to go in a new C++ project. I favor exceptions over return codes (for exceptional cases only) for the following reasons - Constructors can't give a return code Decouples the failure path (which should be very rare) from the logical code which is cleaner Faster in the non-exceptional case (no che...

How do I use QTextBlock?

Hi all, I'm completely new to c++ and Qt. I want to populate a QTextEdit object with QTextBlocks, how do I do that? e.g. If I have the sentence "the fish are coming" how would I put each word into its own QTextBlock and add that block to QTextEdit, or have I misunderstood how QTextBlock actually works? ...

Calling pointer-to-member function in call for a function passed to a template function.

This is the provided function template I'm trying to use: template <class Process, class BTNode> void postorder(Process f, BTNode* node_ptr) { if (node_ptr != 0) { postorder( f, node_ptr->left() ); postorder( f, node_ptr->right() ); f( node_ptr->data() ); } } This is my call, and the function I'm passing: v...

Unix C++ simple server question: sending data back to browser

Hi. I am creating a simple Unix server written in C++ that simply waits for incoming connections, and then when a connection is established, it sends the requested data back to the client's browser to be displayed. I have everything working except for the sending of the data to the client. This is how it should work: I start server and...

including .h file from a different application/directory

I have some .h files as follows (on Linux) Source/Server/connect.h Source/Server/message.h ... I am developing another application that needs the two .h files but is in a different directory Source/App2/.. How can I include the connect.h file in the App2 application, considering that I use perforce and everyone else working on the ...

Pipe communication C++

I´m writing two litle c++ apps that must communicate. First one will be a service which, every once in a while, must alert the user for something. Since a service cannot create windows I designed the app to be two separate executables. The service will use a notifier to communicate. The service needs only to send text messages to the n...

Disallow any member function to change its data members in C++ Class

So how i can do this? So that no member function can change the value of its data members once object has been initialized in C++. ...

Best practices: Where should function comments go in C/C++ code?

So... I understand this might be subjective, but I'd like some opinions on what the best practice for this is. Say I have the following header and .cpp file: header: // foo.h class foo { public: int bar(int in); }; cpp: // foo.cpp int foo::bar(int in) { // some algorithm here which modifies in and returns the modified val...

Correct way to write console applications on GNU/Linux with C++

I really like the console and got recently hooked on programming console applications using nCurses mainly in conjunction with the C programming language. Unfortunately i think the ncurses API is totally borked and very hard to use, and the C++ bindings are undocumented. So my question is, what is THE API to use for C++ console applic...