Skip to main content

Posts

Showing posts with the label FAQ

Complex numbers library

The complex library implements the complex class to contain complex numbers in cartesian form and several functions and overloads to operate with them: Classes complex                             Complex number class (class template) Functions Complex values: real       Return real part of complex (function template) imag     Return imaginary part of complex (function template) abs       Return absolute value of complex (function template) arg       Return phase angle of complex (function template ) norm    Return norm of complex number (function template) conj     Return complex conjugate (function template) polar    Return complex from polar components (function template ) Transcendentals overloads: cos                  Return cosine of complex (func...

How To Take Screen Short of Your Output of Program

Ever Wonder how to take a snap of your output of C++ or C programming. Today we will tell how to do it. some simple step will take a good screen snap of your program or its out put on pc laptop. Here What you have to do 1. Make Program u want to take pic of . 2. Click Alt + Enter And you will see this 3. Now Click PrtScsysrq   button which can be found on the top line of your key board. after the F12 key or     above the number pad if u use keyboard in pc. Well its Done !!!!!! Just past it on the paint and edit.

Shallow And Deep copying

A shallow copy means that C++ copies each member of the class individually using the assignment operator. When classes are simple (eg. do not contain any dynamically allocated memory), this works very well. For example, let’s take a look at our Cents class: class Cents { private:     int m_nCents; public:     Cents(int nCents=0)     {         m_nCents = nCents;     } }; When C++ does a shallow copy of this class, it will copy m_nCents using the standard integer assignment operator. Since this is exactly what we’d be doing anyway if we wrote our own copy constructor or overloaded assignment operator, there’s really no reason to write our own version of these functions! However, when designing classes that handle dynamically allocated memory, memberwise (shallow) copying can get us in a lot of trouble! This is because the standard pointer assignment operator just copies the address of the pointer — it does not ...

What is "genericity"?

FAQ : A way to say "class templates". Don't confuse with "generality". FQA : Hmm, why do we need three ways of saying this? Apparently C++ promoters consider templates an excellent and unique feature, despite their obscurity and the availability of much better meta-programming facilities in many languages. The many different synonyms are probably needed to illuminate the killer feature from many different directions.

What's the idea behind templates?

FAQ: A template describes how to build definitions (classes or functions) which are basically the same. One application is type-safe containers; there are many, many more. FQA: Let's get a bit more specific. The FAQ's answer is applicable to C macros, Lisp macros, ML functors, functions like eval found in many interpreted languages, OS code that generates assembly instructions used to handle interrupts at run time, and just plain code generation (writing programs that print source code). The purpose of all such devices is meta-programming - writing code that works with code, creating pieces of code which are "basically the same" (after all, they are built from the same rules), and yet have some interesting differences. The question is, how do we specify these rules and these differences? The approach used in C++ templates is to use integral constants and types to represent the differences, and to use class & function definitions to represent the rules. T...

Should my class declare a member function or a friend function?

FAQ: Use a member function unless you must use a friend function. For example, you may need friend for operator overloading. FQA: The FAQ says it at last! See? It was about operator overloading all the way. The FAQ's advice may be further simplified if we use the observation that C++ operator overloading is just a pain in the neck.

Do friends violate encapsulation?

FAQ : On the contrary - they enhance it. If used properly, of course. For example, you can use them to split code into two classes and have their data inaccessible for code in all other classes. Or you can use them as "a syntactic variant" of member functions. Think of the friends as part of the class interface instead of something outside the class. FQA: What encapsulation? C++ doesn't have encapsulation. It has access control (code outside of a class using private members of this class will not compile), but it has neither compile time encapsulation (stable binary interfaces) nor run time encapsulation (safe memory access). What's there to violate? The case of two classes was discussed in the previous FAQ; this argument only sounds convincing if you think C++ classes are a good way to define the important, stable interfaces in your system. As to the "syntactic variant" business, it's probably about overloaded operators. The C++ syntax make...

Is Encapsulation a Security device?

FAQ: No. Encapsulation is about error prevention. Security is about preventing purposeful attacks. FQA : Depends on the kind of "encapsulation". Some managed environments rely on their support for run time encapsulation, which makes it technically impossible for code to access private parts of objects, to implement security mechanisms. C++ encapsulation evaporates at run time, and is almost non-existent even at compile time - use #define private public before including a header file and there's no more encapsulation (correction). It's hardly "encapsulation" at all, so of course it has no security applications - security is harder than encapsulation. The capital E and S in the question are very amusing. I wonder whether they are a manifestation of Deep Respect for Business Values or Software Engineering; both options are equally hilarious.