c++

Why does my C++ code fail to delete all nodes in my BST?

This is supposed to traverse a BST and delete every node, including the root node. However, at the end, I get the message "root still has a left node." Why aren't all nodes deleted? void deleteTree() { deleteNode(root); if(root->right) cout << "root still has a right node" << endl; if(root->left) cout <<...

Using 'virtual' in derived class

I saw code in a derived class recently in which the programmer put virtual in front of the functions overridden. Is this common? I thought it was very odd and it kind of caught me off guard. Edit: I'm not asking what virtual does, I'm asking why someone would put virtual in a derived class that is already overriding virtual functions i...

How to print out a BST in C++

My C++ program creates a binary search tree. I know how to print out the values in pre-order, post-order, and in-order. However, I want to do something a little more difficult. I want to print out the values the way they would look if someone drew the tree on paper. It would have the root at the center at the top, it's left child rig...

How to rebuild a BST from a file

My C++ program creates an unbalanced BST from user input, and saves it do disk. It does this by first indexing each node by doing a pre-order traversal and assigning each node a unique number. Next, it outputs the BST to a file. It does this by doing a pre-order traversal and then for each node printing to file the data value, the ind...

How to convert these lines of c code to c++

I'm trying to import some c code into my c++ program. There are three lines that don't import directly: The first: free(t); The second: new_node = (Tree *) malloc (sizeof (Tree)); The third: Tree * delete(int value, Tree * t) How can these be changed to work in C++? ...

unmanaged c++ dll called from c#, crashes when CString used in dll

Hello Most excellent Stackoverflowians Using visual studio 2008 Team System, I have a c++ dll (mfc statically linked regular dll) which has a simple function extern "C" __declspec(dllexport) int MyExportedFunction( ) { AFX_MANAGE_STATE(AfxGetStaticModuleState( )) CString tempString ; .... } The DLLImport from the c# applica...

When comparing for equality is it okay to use `==`?

When comparing for equality is it okay to use ==? For example: int a = 3; int b = 4; If checking for equality should you use: if (a == b) { . . . } Would the situation change if floating point numbers were used? ...

Testing for Type Equality without RTTI

Say B and C are derived from A. I want to be able to test whether any two instances of classes derived from A are instances of the same class, that is, whether A* foo and A* bar both point to B instances, without using RTTI. My current solution is something like this: class A { protected: typedef uintptr_t Code; virtual Code co...

Vista / Win 7 SDK bufferoverflowu.lib linking error

Hey All, I downloaded the Windows SDK 7.0A to explore some things I was reading about. I downloaded some samples that work with the SDK but when I try to compile them I get an error. I looked in the Lib directory of the SDK and couldn't find it. I also did a full system search and also did not find it. I have read about this being a spe...

Help streaming over http in C++

I'm looking to use a web service that offers a streaming api. This api can typically be used by the java method java.net.URL.openStream(); Problem is I am trying to design my program in C++ and have no idea what libraries (I've heard the cUrl library is very good at this sort of thing) to use, or how to use them to do what I want. The...

C structure and C++ structure

Could anybody please tell me what is the main difference between C & C++ structures. ...

converting c style string to c++ style string

Hi, Can anyone please tell me how to convert a C style string (i.e a char* ) to a c++ style string (i.e. std::string) in a C++ program? Thanks a lot. ...

STL compilation error when defining iterator within template class

The code below gives the error: error: type ‘std::list<T,std::allocator<_Tp1> >’ is not derived from type ‘Foo<T>’ error: expected ‘;’ before ‘iter’ #include <list> template <class T> class Foo { public: std::list<T>::iterator iter; private: std::list<T> elements; }; Why and what should this be to be correct?...

regarding file i/o in c++

I have a part of a code that does the following: It reads in sentences from a file in a particular format, puts them in a vector. To probe whether the strings in the vector are stored correctly, I put debugging cout statements. I found that the last string member member of the vector is "". Why is this so? The file I am reading from ends...

MIDL doesn't want me to define a HRESULT-less function!

Hello folks, I'm writing a custom ATL ActiveX component, but I'm having this little weeny problem: Visual Studio insists that every function defines in the *.idl file has to have a HRESULT return type, even though I want to have a ULONG return type. [id(3), helpstring("method addh3h3")] ULONG addh3h3([in] ULONG x, [in] ULONG y); It gi...

Initializing members with members

This is a problem I come across often. The following examples illustrates it: struct A { int m_SomeNumber; }; struct B { B( A & RequiredObject ); private: A & m_RequiredObject; }; struct C { C( ); private: A m_ObjectA; B m_ObjectB; }; The implementation of the constructor of C looks something like this: C::C...

Is it possible to use different tags files for omnicomplete and general tag browsing in Vim?

Hi, I've been using ctags in Vim for years, but I've only just discovered omnicomplete. (It seems good.) However, I have a problem: to get omnicomplete working properly I have to use the --extra=+q option when generating the tags, which is fine, but this then changes the behaviour of general tag browsing in ways that I do not like. F...

Is multiple inheritance acceptable for nodes in a tree?

I was wondering: With a tree, the root can have multiple children and no id. All nodes (except the root) have an id and the leaf nodes can not have children. It is fixed what type must be used for each depth. So the leaves are always of the same type and so are the parents of the leaves. Since the root and the nodes can have children a...

Memory allocation for _M_start and _M_finish in a vector

I'm defining a vector as: vector< int, MyAlloc< int> > *v = new vector< int, MyAllooc< int> > (4); MyAlloc is allocating space for only 4 ints. Memory for _M_start, _M_finish, and _M_end_of_storage is being allocated on the heap before the memory for the 4 ints. But who is allocating this memory for _M_start, _M_finish, and _M_end_of_...

Moving C++ objects, especially stl containers, to a specific memory location

I am working with a memory manager that, on occasion, wants to defragment memory. Basically, I will go through a list of objects allocated by the memory manager and relocate them: class A { SomeClass* data; // This member is allocated by the special manager }; for(... each instance of A ...) a.data = memory_manager.relocate(a.da...