A friend constructor is a constructor that is declared a friend of another class and that grants that constructor private access to the class in which it is declared a friend.
Example:
class Y { friend char* X::foo (int); // friend function friend X::X (char); // constructors can be friends friend X::~X(); // destructors can be friends };
For more information, see '11.3 Friends' in the current ISO C++ Standard.
What do you mean by running of a program in c plus plus?
In order to run a C++ program the program must be compiled and linked to create an executable. It is the executable that actually runs, not the source code. The source code is simply the human-readable code the compiler requires to generate object code for the linker which produces the machine-readable code.
However, when the executable is executed within a debugging environment, we can set breakpoints in the source code and step through the source code just as if the source itself were executing, as would be the case if C++ were an interpreted language. Unlike an interpreted language where we can change the source code and see the results immediately, the source code (or at least the portion that has changed) must be recompiled to accommodate the changes.
Which desktop application use c plus plus?
There are very few applications of any note that aren't written in C++ (or some combination of C++ and C). Even the Java virtual machine required to interpret Java programs is written in C++.
What keyword is used to find derivative in C plus plus?
The lazy way is to use a dynamic cast. The correct way is to use virtual functions in the base class. That way you don't ever need to know the derived type -- it simply does what is expected of it.
What is the Practical application of a derived class object stored in base class pointer?
If you have base class derived object pointing by base class pointer, then you have the power of run time polymorphism in your hand, which gives you the ability to call the derived class implementation of the virtual member function. If we declare the member function as virtual in base class which needs to overridden in derived class, then you can decide at run time which implementation will be called at run time.
What language does Nintendo use for the dsi you are guessing c plus plus?
Java mostly l :: scroll right
Is C plus plus used to write banking software?
It can be, but there is no criteria stipulating that it must be. Banking isn't a black-art so virtually any language could be used so long as security isn't compromised. Speed and efficiency are important at the server side, but much less so at the client-side, so a combination of languages is also possible.
How can write the name in c plus plus language without using cout statement?
I believe, you can use C-function - printf().
The application where c language can't implemented but it is done by c plus plus language?
Any C++ application that makes use of classes cannot be compiled in C since C is not an object-oriented programming language. The code may be altered to eliminate the classes, but if the classes are designed with complex hierarchies then the transition could prove quite difficult to implement.
Why in function overloading name of function is same?
If the function names were not the same then they would not be overloads they'd just be ordinary functions. In reality, there is nothing special about overloads; they are treated just as if they had completely unique names. The compiler uses the name of a function in conjunction with the number and type of arguments passed to it by the caller to determine which function to actually call, whether the function is an overload or not. If no matching signature can be found, or there are two or more overloaded functions with the same signature, the compiler will alert you to the ambiguity. Note that the return type is not considered part of the function signature, hence overloads cannot differ by return type alone. If you need the same signature but a different return type, then you cannot use an overload, you must use a different function name in order to differentiate them.
The reason we use overloads rather than separate function names is merely one of convenience. If overloads were not permitted, then we'd be forced to use unique names for every function, even if the implementations were exactly the same and the only difference was in the type of argument being passed. That, in turn, would mean we could not use template functions (which allow the compiler to generate overloads for us), and we'd then be forced to write and maintain duplicate code ourselves.
C plus plus program to swap two numbers using friend function as a bridge?
There is no need to use a class to swap two numbers. A template function is all you really need. The following example includes both a template function and a class template with a static method. The template function is clearly the easier of the two to use.
#include<iostream>
template<typename T>
void swap(T& x, T&y)
{
T temp=x; x=y; y=temp;
}
template<typename T>
class foo
{
public:
static void swap(T& x, T& y){T temp=x; x=y; y=temp;}
};
int main()
{
int a=40, b=2;
std::cout<<"a is "<<a<<", b is "<<b<<std::endl;
swap(a,b);
std::cout<<"a is "<<a<<", b is "<<b<<std::endl;
foo<int>::swap(a,b);
std::cout<<"a is "<<a<<", b is "<<b<<std::endl;
}
Example output:
a is 40, b is 2
a is 2, b is 40
a is 40, b is 2
A hip pointer is a deep bruise on the side of your hip. It feels like a big charlie horse, or like a football players helmet ramming into the side of your hip. It takes time and alot of rest for it to heal correctly. Also it is important to keep an icing it for 2-3 days, every 20 minutes, with 10-15 minute break. If it hurts more than 2 weeks, than you should probably get an x-ray.
Write a c plus plus function to reverse the contents of a stack using two additional stacks?
The following function template will reverse any stack of type T:
template<typename T>
void reverse_stack (sd::stack<T>& A) // Pass by reference!
{
std::stack<T> B, C; // Two additional stacks (initially empty).
while (!A.empty()) { B.push (A.top()); A.pop(); }
while (!B.empty()) { C.push (B.top()); B.pop(); }
while (!C.empty()) { A.push (C.top()); C.pop(); }
// A is now in reverse order.
}
A more efficient method is to pop the stack onto a queue.
template<typename T>
void reverse_stack_optimised (sd::stack<T>& A) // pass by reference!
{
std::queue<T> B;
while (!A.empty()) { B.push_back (A.top()); A.pop(); }
while (!B.empty()) { A.push (B.front()); B.pop(); }
// A is now in reverse order.
}
What kind of an error in c plus plus is dividing by zero?
The answer is in your own question. A divide by zero error is a divide or mod by zero type of error. In MSVC++ it has the error code C2124. Ultimately it is a fatal error and will either produce a compile time error or throw an unhandled exception at runtime.
How would you access data members of a class in cases inside member function of another class?
Either make the data members public, or make the member function a friend of the class containing the data member.
How to write your own function for standard library functions strcat strcpy strcmp?
Though i cannot think of a reason do to it (why not use the available methods in the string.h ?) , it is possible to do it manually.
Loop through your character arrays and compare / copy.
Suppose you are char orig[100];
strcmp:
for (int i=0; orig[i] != 0; i++)
if (orig[i] != other[i]) return false;
return true; // because reached the end of the string.
and copy will be similar:
first get the length:
int length = 0;
for (int i=0; orig[i] !=0; i++, length++);
char *other = new char[length];
for (int i=0; i < length; i++)
other[i] = orig[i]; // will also copy the \0
return 0;
}
strcpy is even simpler:
char *strcpy(char *dest, const char *src)
{
char *s = dest;
while (*dest++=*src++)
;
return s;
}
strcat is similar to strcpy, but it first finds the end of the dest string before copying the src string to it. I'll leave that as an exercise to the reader.
What is the return value when new operator is not able to allocate memory in c?
There is no operator new in C.
In C++11, there are three versions of operator new, all of which can be overridden. Default behaviour is as follows:
(1) throwing allocation
void* operator new (std::size_t size);
If an allocation of the given size cannot be met, an exception will be thrown. There is no return value after an exception is thrown.
(2) nothrow allocation
void* operator new (std::size_t size, const std::nothrow_t& nothrow_value) noexcept;
If an allocation of the given size cannot be met, nullptr is returned.
(3) placement
void* operator new (std::size_t size, void* ptr) noexcept;
Always returns ptr. You use this version when memory has already been allocated and you are merely providing placement for an object within that allocation.
What is multidimensional array in c plus plus?
A multidimensional array in C or C++ is simply an array of arrays, or an array of an array of arrays, etc. for however many dimensions you want.
int a; // not an array
int a[10]; // ten int a's
int a[10][20]; // twenty int a[10]'s, or 200 int a's
int a[10][20][30]; // and so on and so forth...
How do you update a data file in c plus plus with a reference?
You cannot store references. A reference is nothing more than an alias, an alternate name for an existing variable or constant. References are primarily used when passing variables to functions such that the function can operate upon the variable itself -- known as passing by reference. The function refers to the variable by a different name, an alias, but it is the same variable. By contrast, when passing a variable by value the function uses a copy of that variable, assigning the variable's value to that copy.
References are often confused with pointers, primarily because C uses the term to mean a pointer (hence the term, dereferencing). But in C++ a reference is a separate entity altogether. Unlike a reference, a pointer is a variable in its own right, one that can be used to store a memory address. Since a pointer has storage, you can store a pointer in a data file. However, in reality you are only storing the pointer's value -- a memory address -- not an actual pointer.
Pointers and references are similar insofar as they can both refer to an object. A pointer does this by storing the memory address of the object, while a reference refers directly to the object itself. Thus if you have a pointer and a reference to the same object, the pointer's value is exactly the same as the address of the reference. Therefore the only way you can store a reference is by storing the object being referred to, not the reference itself.
What is the difference between c and c plus plus extension?
c language is the structure oriented language and c does not follows the object oriented paradigms . c++ obeys the all object oriented language characteristics
==========
C++ is a set of extensions to the C language to allow some (not all) principles of object-oriented programming to be used. Originally, C++ was a front end pre-processor for C and C++ compilers will translate C language functions.
Should the constructor name and class name be same?
Every class object is created using the same new keyword, so it must have information about the class to which it must create an object. For this reason, the constructor name should be the same as the class name.
To learn more about data science please visit- Learnbay.co
Why to take two arguments in binary operator overloading using friend function?
Binary operators require two operands (l-value and r-value) and therefore require two arguments when overloading via external functions. When overloading class member operators, the l-value is the class instance itself (the implicit this pointer), therefore only the r-value need be given as an argument.