Why does the C++ STL not provide any "tree" containers, and what's the best thing to use instead?
I want to store a hierarchy of objects as a tree, rather than use a tree as a performance enhancement...
...
I have code like this:
template <typename T, typename U> struct MyStruct {
T aType;
U anotherType;
};
class IWantToBeFriendsWithMyStruct
{
friend struct MyStruct; //what is the correct syntax here ?
};
What is the correct syntax to give friendship to the template ?
...
[This question is related to but not the same as this one.]
If I try to use values of certain types as boolean expressions, I get a warning. Rather than suppress the warning, I sometimes use the ternary operator (?:) to convert to a bool. Using two not operators (!!) seems to do the same thing.
Here's what I mean:
typedef long T; ...
I need a way to determine whether the computer running my program is joined to any domain. It doesn't matter what specific domain it is part of, just whether it is connected to anything. I'm coding in vc++ against the Win32 API.
...
I am declaring an array of void pointers. Each of which points to a value of arbitary type.
void **values; // Array of void pointers to each value of arbitary type
Initializing values as follows:
values = (void*)calloc(3,sizeof(void));
//can initialize values as: values = new void* [3];
int ival = 1;
float fval = 2.0;
...
Is there a way to hide private data members of a C++ class away from its users, in the cpp file? I think of the private members as part of the implementation and it seems a little backwards to declare them in the header file.
...
Creating Traversals for Binary Search Tree with Recursion.
void inOrder(void (*inOrderPtr)(T&))
{
if(this->left != NULL)
inOrder((*inOrderPtr)(this->left));
inOrderPtr(this->data);
if(this->right != NULL)
inOrder((*inOrderPtr)(this->right));
}
Here is the function. Now this is obviously wrong. Th...
[This question is related to but not the same as this one.]
My compiler warns about implicitly converting or casting certain types to bool whereas explicit conversions do not produce a warning:
long t = 0;
bool b = false;
b = t; // performance warning: forcing long to bool
b = (bool)t; // perform...
My studio has a large codebase that has been developed over 10+ years. The coding standards that we started with were developed with few developers in house and long before we had to worry about any kind of standards related to C++.
Recently, we started a small R&D project in house and we updated our coding conventions to be more suita...
I would like to implement a producer/consumer scenario that obeys interfaces that are roughly:
class Consumer {
private:
vector<char> read(size_t n) {
// If the internal buffer has `n` elements, then dequeue them
// Otherwise wait for more data and try again
}
public:
void run() {
read(10);
re...
After some find and replace refactoring I ended up with this gem:
const class A
{
};
What does "const class" mean? It seems to compile ok.
...
I need to know when my Window goes out of input focus, so I overloaded the OnKillFocus() method of the CWnd.
However it doesn't invoke this method when I focus another application (alt+tab), or even minimize the window. But it DOES invoke the method when I restore it from being minimized. Are these the intended times for it to trigger ...
I am a CS student currently learning C. I'd like to get into low level programming, whether as a hobby or career and may contribute to some open source projects down the line. So far I really enjoy C and think I will continue down the abstraction level and take ASM next semester.
The question I have is this, is knowing C enough to be a...
template <class T>
void BT<T>::inOrder(void (*inOrderPtr)(T&))
{
inOrderPtr(inOrder(this->root));
}
template <class T>
void BT<T>::inOrder(Node<T>* root) const
{
if (root->left != NULL)
inOrder(root->left);
//something here
if (root->right != NULL)
inOrder(root->right);
}
Ok I am trying to create t...
So my code is below. I'm not getting any errors and it places everything in the node just fine. But based on my debug statements Everytime anything is inserted it's finding the root. I'm not sure if that is right. But according to output file for the assignment, my answers are different when it comes to the height of the tree, the tr...
I'm trying to write a wstring to file with ofstream in binary mode, but I think I'm doing something wrong. This is what I've tried:
ofstream outFile("test.txt", std::ios::out | std::ios::binary);
wstring hello = L"hello";
outFile.write((char *) hello.c_str(), hello.length() * sizeof(wchar_t));
outFile.close();
Opening test.txt in for ...
I'm trying to create a C++ class, with a templated superclass. The idea being, I can easily create lots of similar subclasses from a number of superclasses which have similar characteristics.
I have distilled the problematic code as follows:
template_test.h:
template<class BaseClass>
class Templated : public BaseClass
{
public:
...
Hi all,
I know how to fill an std::vector with non-trivial initial values, e.g. sequence numbers:
void IndexArray( unsigned int length, std::vector<unsigned int>& v )
{
v.resize(length);
for ( unsigned int i = 0; i < length; ++i )
{
v[i] = i;
}
}
But this is a for-loop. Is there an elegant way to do this with ...
I've a dialog which contains a QT TabWidget with a number of tabs added.
I'd like to hide one of the tabs.
_mytab->hide()
doesn't work. I don't want to just delete the tab and all its widgets from the .ui file because other code relies on the widgets within the tab. However, it would be fine to generate the tab code but somehow ...
I came across a class instance function that needed to temporarily change a class instance variable, and then restore it when the function completed. The function had return statements all over the place, and before each return there was a restoring statement. That seemed messy to me, not to mention scary when a exception is thrown.
As ...