c++

Adding C++ template classes to a list

Hi, I have a template class, C_Foo<T>, which is specialised in a number of ways. struct Bar_Base { ... }; struct Bar_1 : public Bar_Base { ... }; struct Bar_2 : public Bar_Base { ... }; struct Bar_3 : public Bar_Base { ... }; class C_Foo<T> { ... }; class C_Foo_1 : public C_Foo<Bar_1> { ... }; class C_Foo_2 : public C_Foo<Bar_2> { .....

Why does cout print char arrays differently from other arrays?

I'm using C++ to understand how exactly pointers work. I have this piece of code using arrays, which I'm using just to understand how the equivalent works with pointers. int main() { int arr[10] = {1,2,3}; char arr2[10] = {'c','i','a','o','\0'}; cout << arr << endl; cout << arr2 << endl; } However when I run th...

In Inheritance: Can I override base class data members??

Lets say I have two classes like the following: Class A { public: .. private: int length; } Class B: public Class A { public: .. private: float length; } What I would like to know is: 1) Is OVERRIDING OF BASE CLASS DATA MEMBERS allowed? 2) If yes, is it a good practice? 3) If no, what is the best way to extend the type of the data...

Erasing items from an STL list

I want to make a function which moves items from one STL list to another if they match a certain condition. This code is not the way to do it. The iterator will most likely be invalidated by the erase() function and cause a problem: for(std::list<MyClass>::iterator it = myList.begin(); it != myList.end(); it++) { if(myCondition(*it))...

Create GUID menu item missing in Visual C++

I do not see "Create GUID" option under the menu item Tools -> . I am using Visual Studio 2005 . Do I have to install anything for that . ...

When do you define the ostream operator << for an class?

The question could be subjective, so the syntax of std::ostream& operator << (std::ostream & o, const SomeClass &a) { return o << a.accessor().. ; } When do you normally define this for the classes that you write, when do you avoid writing this friend function for your class. ...

Passing "const" variable to method in Java

Is there an equivalent in Java to the passing on const references in C++? Isn't leaving out the "constness" misleading in regard to the method signature? ...

Should I wrap all my c++ code in its own namespace?

I come from a c# background where everything has its own namespace, but this practice appears to be uncommon in the c++ world. Should I wrap my code in it's own namespace, the unnamed namespace, or no namespace? ...

Prime numbers

Hi, I'm currently trying out some questions just to practice my programming skills. ( Not taking it in school or anything yet, self taught ) I came across this problem which required me to read in a number from a given txt file. This number would be N. Now i'm suppose to find the Nth prime number for N <= 10 000. After i find it i'm supp...

Disable/Enable Ribbon Buttons for MFC Feature Pack

I am using the MFC Feature Pack and I have some buttons on a ribbon bar, instances of CMFCRibbonButton. The problem is that I would like to enable and disable some of them in certain conditions, but at runtime. How can I do this? because there is no specific method for this...I heard that a solution would be to attach/detach the event ha...

vc++ Line Graph Example

Can someone please provide me with a hint on how to draw a line graph in vc++ 6.0? ...

What's the difference between size_t and int in C++?

In several C++ examples I see a use of the type size_t where I would have used a simple int. What's the difference, and why size_t should be better? Thank you folks. ...

How to deal with SQL Server from native C++ on the Windows platform?

Is there any solution other than the ugly ADO as it is not good and badly documented? ...

axxdsp.h in Visual Studio 2008

I have a dll which builds properly in VS 2005 . The dll includes "afxdisp.h" header file which is present in the default location (C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include) . // piece of code ifndef _AFX_NO_OLE_SUPPORT #include "afxdisp.h" endif // ends The same dll is not building in Visual Studio 2008 . ...

What function was used to code these passwords in AFX?

I am trying to work out the format of a password file which is used by a LOGIN DLL of which the source cannot be found. The admin tool was written in AFX, so I hope that it perhaps gives a clue as to the algorithm used to encode the passwords. Using the admin tool, we have two passwords that are encoded. The first is "dinosaur123456789"...

How to debug file change notifications obtained by FindFirstChangeNotification?

So, the question is: I get some notifications I don't want to get. But I don't know for what file/dir I got them. Is there a way to know why given notification was fired? If you think about ReadDirectoryChangesW, please include a meaningful code sample. ...

How can I get the current users permission groups?

I have a Qt/C++ project and an old VB6 project. The user base might not have permissions to HKEY_LOCAL_MACHINE due to lack of administrator rights but I need to update a registry entry. How can I get a list of the groups to which a user belongs? ...

How to deal with excess precision in floating-point computations?

In my numerical simulation I have code similar to the following snippet double x; do { x = /* some computation */; } while (x <= 0.0); /* some algorithm that requires x to be (precisely) larger than 0 */ With certain compilers (e.g. gcc) on certain platforms (e.g. linux, x87 math) it is possible that x is computed in higher than dou...

Image Processing Library for C++

I need a library that can detect objects in an image (uses edge detection). This is NOT related to captchas. I am working on an MTGO bot that uses OCR and that works in any screen resolution. In order for it to port to any screen resolution my idea is to scan down narrow range on a results page (the cards that a player has can be listed ...

Member functions for derived information in a class

While designing an interface for a class I normally get caught in two minds whether should I provide member functions which can be calculated / derived by using combinations of other member functions. For example: class DocContainer { public: Doc* getDoc(int index) const; bool isDocSelected(Doc*) const; int getDocCount() const...