Do you know the problem with overriding functions?
Answer / Vivek Bhardwaj
Overriding functions can lead to unintended behavior if not implemented properly. One common issue is that derived class objects may behave unexpectedly when used in a context where they should be treated as base class objects. Additionally, changing the behavior of an inherited function can break existing code that relies on the original functionality.
| Is This Answer Correct ? | 0 Yes | 0 No |
what is the use of Namespace in c++.
Explain RAII (Resource Acquisition Is Initialization).
Which function cannot be overloaded c++?
What is RAII (Resource Acquisition Is Initialization)?
What are the storage qualifiers?
Why c++ is faster than java?
Why do we use iterators?
What is difference c and c++?
What is fflush c++?
class Alpha { public: char data[10000]; Alpha(); ~Alpha(); }; class Beta { public: Beta() { n = 0; } void FillData(Alpha a); private: int n; }; How do you make the above sample code more efficient? a) If possible, make the constructor for Beta private to reduce the overhead of public constructors. b) Change the return type in FillData to int to negate the implicit return conversion from "int" to "void". c) Make the destructor for Alpha virtual. d) Make the constructor for Alpha virtual. e) Pass a const reference to Alpha in FillData
Find out the bug in this code,because of that this code will not compile....... #include <iostream> #include <new> #include <cstring> using namespace std; class balance { double cur_bal; char name[80]; public: balance(double n, char *s) { cur_bal = n; strcpy(name, s); } ~balance() { cout << "Destructing "; cout << name << "\n"; } void set(double n, char *s) { cur_bal = n; strcpy(name, s); } void get_bal(double &n, char *s) { n = cur_bal; strcpy(s, name); } }; int main() { balance *p; char s[80]; double n; int i; try { p = new balance [3]; // allocate entire array } catch (bad_alloc xa) { cout << "Allocation Failure\n"; return 1; }
What is the function to call to turn an ascii string into a long?