c++

Nested class definition in Abstract Base Class (C++)

Are there any suggestions on how to use a nested class iterator in an ABC in C++ ? Note that, I also want to have a virtual function returning an instance of this class. More specifically here's my approach: class ABC { typedef iterator<forward_iterator_tag, MyType> MyTypeIter; virtual MyTypeIter *begin() = 0; }; clas...

Differences between dynamic memory and "ordinary" memory

What are some of the technical differences between memory that is allocated with the new operator and memory that is allocated via a simple variable declaration, such as int var? Does c++ have any form of automatic memory management? In particular, I have a couple questions. First, since with dynamic memory you have to declare a pointer...

SendInput() Keyboard letters C/C++

I am trying to use SendInput() to send a sentence to another application (Notepad) and then send it hitting the Enter Key. Any code snippets? Or help ...

Programming slim C++ programs (like uTorrent) for Windows

I've always admired the original uTorrent program. It looked great, was less than 64kb, was extremely fast and had all the features I needed. Unfortunately the program is closed source (and becoming more bloated by the day) so I come to Stackoverflow for inspiration. What methods do you recommend in writing fast, memory efficient and el...

How to tell std::set to 'refresh' its ordering?

If the value of an element in a set changes the ordering may be no longer correct. As illustrated in this little program: #include <algorithm> #include <iostream> #include <set> #include <string> struct Comp { bool operator()(const std::string * lhs, const std::string * rhs) { return *lhs < *rhs; } }; int main() { ...

Which is preferred: foo(void) or foo() in C++

I have seen two styles of defining conversion operator overload in C++, operator int* (void) const operator int*() const Question 1. I think the two styles (whether add void or not) have the same function, correct? Question 2. Any preference which is better? ...

Brushing up a knowledge of C++, C#, ASP.NET and Design patterns

I've been a software developer for 10 years and came all the way from a wild world of assembly language programming, then server side of C++ and COM, and for the last 5 years I was comfortably settled in a quiet world of .NET, C# and development of business applications. The problem is - the last couple of years was so comfortable and I...

wrapping #includes in #ifndef's - adds any value?

I have inherited C/C++ code base, and in a number of .cpp files the #include directives are wrapped in #ifndef's with the headers internal single include #define. for example #ifndef _INC_WINDOWS #include <windows.h> #endif and windows.h looks like #ifndef _INC_WINDOWS #define _INC_WINDOWS ...header file stuff.... #endif // _INC_WIN...

COM-like interfaces warn about non virtual destructor

Is there a way to tell gcc that the abstract class it's compiling does not need a virtual destructor (like COM-objects never have)? For example nsISupports always complains about the missing virtual destructor. Turning off the warning would not help as I may have non-COM-like classes, where I want this warning. So __attribute__((com_int...

How does STL algorithm work independent of Iterator type?

How does STL algorithm work independent of Iterator type? ...

C++: Could Polymorphic Copy Constructors work?

Consider: class A { public: A( int val ) : m_ValA( val ) {} A( const A& rhs ) {} int m_ValA; }; class B : public A { public: B( int val4A, int val4B ) : A( val4A ), m_ValB( val4B ) {} B( const B& rhs ) : A( rhs ), m_ValB( rhs.m_ValB ) {} int m_ValB; }; int main() { A* b1 = new B( 1, 2 ); A* b2 = new A( ...

Can a Class be self-referenced?

**If a structure can be a self-referential. like struct list { struct list *next; }; as there is no difference between class and struct, except the default access specifiers. then is it possible to write a class... class list { class list *next; }; or may be is there any different syntax to get a self-referential class.? ...

How do I forward declare an inner class?

I have a class like so... class Container { public: class Iterator { ... }; ... }; Elsewhere, I want to pass a Container::Iterator by reference, but I don't want to include the header file. If I try to forward declare the class, I get compile errors. class Container::Iterator; class Foo { void Read(Container...

How to generate C++ Dynamic Objects names ?

I'd like to generate a number of objects (in C++) based on the amount/number the user enters. Now I've somewhere heard that it has to be done using pointer tricks, creating a pointer to an array of the Object type required, and then dynamically increasing the size of array ( at runtime ). Isn't there a workaround of directly using name...

How to test a C++ library usability in configure.in?

Hi, I'm working on a C++ project on GNU/Linux and I'm looking for a way to test the existence and usability of IBM Informix's library with the Autotools - namely, editing a configure.in. I don't have experience with AutoTools, so basically I'm picking up from the project's configure.in et al. scripts and copying&changing where I feel ne...

Question concerning Win32 Console app vs. CLR Console app

Hello, I'm working on a C++ project that I don't intend to develop or deploy using .NET libraries or tools, which means it would make sense for me to create it using a Visual Studio Win32 Console application. However, I've heard that the debugging abilities when using a CLR application under Visual Studio are much more powerful. So I ...

Overriding same method in only some child classes, how to avoid duplication?

I am using a base class and there are 5 child classes currently for it. Some of the functions are similar for 3 of the children but not all of them. I cannot introduce a new level of hierarchy as some methods are repeated in child 1,2,3 and some in 2,3,4. How best can I avoid overriding the methods in all 3 children and repeating the co...

why destructor is not called implicitly in placement new"?

As referenced in this site... http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.10 But i did not find the reason, why we should explicitly call the desturctor? ...

How to create a temporary text file in c++?

Hi, I'm trying to create a temporary text file in c++ and then delete it at the end of the program. I haven't had much luck with google. Could you tell me which functions to use? Thanks. edit: The answers below tell me how to create a temp file. What if I just want to create a file (tmp.txt) and then delete it? How would I do that?...

Looking for design pattern

Hello All, I have a problem in which on request one process requests multiple instances (processes) of there state and after collecting data, manipulates the data and represents to the requestor. Could you please suggest me any design pattern which solves this problem?. -thanks Harish ...