c++

Understanding the design of std::istream::read

std::istream has the prototype istream& read (char* s, streamsize n) the actual number of bytes read should be gotten by calling istream::gcount(), also the validity of the istream can be known from ios::good. I was discussing another stream class' implementation I was trying to write with a colleague of mine, where I was saying I might...

How to force AfxMessageBox to center on mainframe and not whatever child window that currently has focus.

I'm developing an MDI application, the primary document is maximized in the MDI frame. I create a non-modal dialog pop-up to display secondary information to the user while they work in the main window. However, when the user moves the pop-up it takes focus which is expected. The problem occurs when this window has focus and an event ...

Transparently manipulating strings inserted into an ostream

I'd like to provide an std::ostream that may or may not, from the user's point of view, encrypt its contents. Imagine some random function that uses an std::ostream&: void write_stuff( std::ostream& stream ) { os << "stuff"; } Whether stuff is output in cleartext or is encrypted is dependent on how the stream argument was initial...

operator= in c++

Possible Duplicate: Trouble with inheritance of operator= in C++ hello everyone, let's assume I have two classes: Base{}; //inside I have operator= Derived{}; //inside I don't have operator= why this one is working perfectly: Derived der1, der2; der1=der2; //<-here I know that it actually calls my Base::operator= and th...

GetPixel in GDI

Using GetPixel, Is that right that you retrieve the pixel information that HDC temporarily store after you draw on each WM_PAINT call? ...

FUSE was hanging when try to get ppid of context when executing files

Hi, all I've tried to insert a piece of code in a prototype file system written in FUSE that can get ppid from the calling process id (fuse_get_context()->pid). It works well for normal read/write operations. However, if one program is going to execute a file (only on Mac OSX), this fs quits after hanging for a long time. The code is fo...

C++ Interop: How do I call a C# class from native C++, with the twist the class is non-static?

Hi, I have a large application written in native C++. I also have a class in C# that I need to call. If the C# class was static, then it would be trivial (there's lots of examples on the web) - just write the mixed C++/CLI wrapper, export the interfaces, and you're done. However, the C# class is non-static, and can't be changed to sta...

C++ templates: Query regarding which is better of way of using and why

I have a got a question. Which is the better of doing it. typedef enum{ One = 1, Two = 2 } Number; template< typename T, Number num > void foo( const T& param ) { } or template< typename T > void foo( const T& param, Number num ) { } What basically I am looking for is, how are these two methods different? If I have to use any ...

For locale-sensitive functions, is it more common to pass the std::locale or the needed facet object(s)?

Recently I wrote a family of functions for trimming leading and trailing whitespace off of an input string. As the concept of "whitespace" is locale-dependent, I realized that I would need to either pass in a const std::ctype<char_t> reference or a const std::locale reference and call std::use_facet<std::ctype<char_t> > on the const std:...

What is the recommended way of working with QActions in multiple level hierarchy of widgets?

I'm planning on using qActions for use globally in my application. The idea is to have an action to be available at any level in the widget parent/child hierarchy. Let's say I have the following GUI: +--------------+ | +----------+ | | | +----+ | | | | | W2 | | | | | +----+ | | | | W1 | | | +----------+ | | MainWindow | +...

Namespace refactoring tool for Eclipse?

I'm doing some housekeeping on some files, and I need to move some classes to a new namespace. Currently I have to manually edit the files, but I was wondering if there's a more efficient way of doing this? I heard about ReSharper for Visual Studio does what I need, but is there a similar tool for Eclipse? ...

C++ whether a template type is a pointer or not

Possible Duplicate: Determine if Type is a pointer in a template function I am looking for a method to determine whether a template is a pointer or not at compiling time. Because when T is not a pointer, the program will not compile as you cannot delete a normal type variable. template <typename T> void delete(T &aVar) { ...

typeinfo / typeid output

I'm currently trying to debug a piece of simple code and wish to see how a specific variable type changes during the program. I'm using the typeinfo header file so I can utilise typeid.name(). I'm aware that typeid.name() is compiler specific thus the output might not be particularly helpful or standard. I'm using GCC but I cannot find...

Overloading increment operator, looping, and edge cases.

Hello! I have an enum, that looks like this: enum Suit {Clubs, Diamonds, Hearts, Spades}; I want to overload the increment operator, so I can easily loop over these four dudes. When the variable is Clubs, Diamonds, or Hearts there no issue. Its the Spades condition that is giving me a little trouble. My first instinct was to define...

C++ simple polymorphism issue

Ok I admit it, I'm a total C++ noob. I was checking the book Data Structures and algorithms in C++ by Adam Drozdek, in the section 1.5 : "Polymorphism" he proposes the next example: class Class1 { public: virtual void f() { cout << "Function f() in Class1" << endl; } void g() { cout << "Function g()...

Create a vector of pointers to abstract objects

I'm sure there's a better way to do this. I'm trying to create a class HashTable that is given a size at instantiation, so it can't be given a size at design time, so I can't use an array as my internal representation of the table, as far as I know. So here's what I'm trying to do: #include <vector> #include <iostream> #include "Nodes...

How could these case conversion functions be improved?

As a learning exercise, my three functions—ToggleCase, LowerCase and UpperCase—each expect a pointer to an ASCII char string, terminated by the null character; they work as expected. Are there more efficient or faster methods of accomplishing this task? Am I breaking any unspoken rules of good C coding? I've made use of macros because...

C++ keeping access to protected member (of the function argument) when specializing base template class

Hi, could anyone please help to resolve this (the problem is persistent under both GCC and VC++). template <class T> class A{ protected: T a; public: A(int aa=0){a=aa;} virtual ~A(){} virtual void plus(A const *AA){a=a+AA.a;} }; class B:public A<int>{ public: B(int bb=0):A<int>(bb){} vir...

convert a console app to a windows app

(its a long story) but I have a large complex project file containing a windows program. Unfortunately the project was originally built as a console app. The program compiles and links ok but when runs brings up a console instead of the collection of windows I was hoping for. I looked at the command line and saw "/SUBSYSTEM:CONSOLE" wher...

modf returns 1 as the fractional:

I have this static method, it receives a double and "cuts" its fractional tail leaving two digits after the dot. works almost all the time. I have noticed that when it receives 2.3 it turns it to 2.29. This does not happen for 0.3, 1.3, 3.3, 4.3 and 102.3. Code basically multiplies the number by 100 uses modf divides the integer value by...