c++

How to prevent duplicated resource ID in different plugins?

In MFC C++, When we add a new resourcein a EXE, says string, it will generate an ID automatically: #define ID_SHOW_OUTPUT 10313 When it has a plugin(DLL) which has the similar ID, it will cause undefined behavior after trigerred. To play safe, I tried to define the my own private ID: #define ID_SHOW_OUTPUT (...

Type conversion for function parameters

class A{ }; class B{ public: B(); B(const &A); }; void foo(A &a){ } int main(){ B b; foo(b); //error: invalid initialization of reference of type ‘A&’ from expression of type ‘B’ return 0; } In the above code, I have a compilation error error: invalid initialization of reference of type ‘A&’ from expression of ty...

CFile::osNoBuffer flag causes exception when writing to file.

(WINAPI create file - WINAPI write file) Flag used in winapi (FILE_FLAG_NO_BUFFERING) works fine, when I use winapi functions to write the file. (WINAPI create file - CFile - write file) In this situation the error also had occured, but it was because of absent file name in CFile object, that was created from the file handle received f...

How-to ensure that compiler optimizations don't introduce a security risk ?

I have to write a Windows service that handles at some point confidential data (such as PIN codes, passwords, and so on). Those informations are needed for a very short amount of time: usually they are sent almost immediately to a smart card reader. Lets consider this piece of code: { std::string password = getPassword(); // Get the ...

C++ access specifiers, too few??

As far as i know, there're only 3 access-specifiers in C++: private, public, protected With these 3 access-specifiers, how can i make a method usable to the classes in the project but unusable to the "foreigners" ??(like internal and public in C#) ...

How-to write a password-safe class ?

This question follows a suggestion made by @sharptooth in this related question. Can std::string be tweaked so that it becomes password-safe ? If not, what would be the guidelines to write a password-handling class (thus a class that takes big care about what it writes to memory and clears it before destruction) ? ...

Difference between virtual and pure virtual function?

Possible Duplicate: C++ Virtual/Pure Virtual Explained what is the exact difference b/w virtual function and pure virtual function and where should we use these functions in which situation? ...

trigonometric funcs

I want to make a sin func. so here's my code: inline double _cdecl Sin(double Rad) { _asm { fld QWORD PTR [Rad] fsin } } my func works faster(ratio of about 6) than the standard sin. (there are probably some problems in it, but it's enough for me) but if I'll do for example for(int i = 0; i < 1000000; ++i...

C++ template type that can be stored in a std::map and then exposing the map publicly.

Hi, I have a class myclass that has a private member param_map class some_class { private: std::map<std::string,std::shared_ptr<parameter> > param_map; }; I want to expose this map to allow other classes, I have already created add, delete, get parameter methods, which do, what you think. But I would like to expose this so other...

what is the meaning of qualifier?

what is the meaning of qualifier and difference between qualifier and keyword? as Volatile qualifier in C and we can say volatile is keyword so waht is the meaning of qualifier? ...

Does using "pointer to volatile" prevent compiler optimizations at all times?

Here's the problem: your program temporarily uses some sensitive data and wants to erase it when it's no longer needed. Using std::fill() on itself won't always help - the compiler might decide that the memory block is not accessed later, so erasing it is a waste of time and eliminate erasing code. User ybungalobill suggests using volat...

Can static allocated memory become invalid during static deinitialization?

Say I have defined a variable like this (C++): static const char str[] = "Here is some string data"; And I have a statically allocated class instance which references this array in its destructor, can this go wrong? E.g. could the str variable somehow get invalid? class A { ~A() { cout << str << endl; } }; static A a; My assu...

MFC Combobox Add A-Z Drives ?

Hi, I have a MFC Combobox i want to add A-Z drives to my combox at runtime Currently i am adding like this m_cmbdrive.AddString("A:"); m_cmbdrive.AddString("B:"); m_cmbdrive.AddString("C:") upto m_cmbdrive.AddString("Z:"); But it seems not to be gud approach . Any modularlize code if any body can help on this ? ...

Keeping memory usage within available amount

I'm writing a program (a theorem prover as it happens) whose memory requirement is "as much as possible, please"; that is, it can always do better by using more memory, for practical purposes without upper bound, so what it actually needs to do is use just as much memory as is available, no more and no less. I can figure out how to prior...

"Virtual" is qualifier or keyword in C++?

"Virtual" is qualifier or keyword in C++? ...

do i need to add this head file "stdafx.h" to run an c++ program in windows

hello, i am new to windows c++ i have created an application in visual studio 2008 and i have created new win32 console and i have compiled an sample c++ program it asked me to add the stdafx header and is it is compulsory to add this header ??? i dont need any windows library.... ...

Access specifiers and virtual functions

What are the rules for accessibility when virtual functions are declared under 3 different access specifiers specified by C++(public, private, protected) What is the significance of each? Any simple code examples to explain the concept will be highly useful. ...

Tools to bracket conditional statement

Does anyone know of a tool which can beautify C++ code to add brackets to conditional statements? What I need to do is change: if ( myCondition ) setDateTime( date, time ); to if ( myCondition ) { setDateTime( date, time ); } but I've got to do this hundreds of times. I could probably write something in perl but don't want ...

how to read an remote file using c++

hello, i need to read an remote file using c++ if it is text or html we can get it though curl and for .mp3 or any other file how can i get the file.... ...

Do I need a visitor for my component ?

I'm trying to do a small and simple GUI in C++ (with SDL). I'm experimenting with the Composite pattern to have a flexible solution. I've got a Widget class, with Component objects : for instance, there is a PaintingComponent ; if I want to draw a box, I'll use a PaintingBoxComponent, that inherits from the PaintingComponent. The ide...