|
Why does this C++ program not compile?
class X { int i; public: X( int ii ) { i = ii; } }; int main() { X xarray[10]; }
Is this C++ program legal?
class X { int i; }; int main() { X xarray[10]; }
The class X does not possess a no-arg constructor, either user-defined or system-supplied. Nonetheless, main declares a vector as shown. Will this C++ program compile?
#include <vector> using namespace std; class X { int i; public: X( int ii ) { i = ii; } }; int main() { vector<X> xvec; }
This C++ program does not compile. Why?
#include <vector> using namespace std; class X { int i; public: X( int ii ) { i = ii; } }; int main() { vector<X> xvec(100); }
Will C++ this program compile and execute?
#include <vector> using namespace std; class X { int i; }; int main() { vector<X> xvec; }
Will this C++ program compile? If it does compile, will it do what the programmer mostly likely wanted it to do?
#include <string> using namespace std; class User { string name; }; class UserGroup { User chief; User uList[10]; }; int main() { UserGroup ug(); }
What is the output of this C++ program?
#include <iostream> #include <string> using namespace std; class User { public: string name; }; class UserGroup { public: User chief; User uList[10]; }; int main() { UserGroup ug; cout << ug.chief.name; cout << ug.uList[0].name; }
It was mentioned in Section 7.2 that when a programmer does not provide a class with any constructors, the class does not get a system-supplied default no-arg constructor if it has a const data member. In the following program, the class Y has not been provided with any constructors at all and it has a const data member. Class X has been provided with a no-arg constructor as shown. The program compiles and runs without errors. Why?
#include <iostream> using namespace std; class Y { public: const int yval; }; class X { public: Y y; int xval; X() {} }; int main() { X x; cout<<x.y.yval<<endl; return 0; }
|