ALTE DOCUMENTE
|
|||
[ C++ ]
C++ access control
// BASE CLASS
class A
~A() ;
int GetP 141f513b rotectedField()
int GetP 141f513b rivateField()
protected:
int m_nP 141f513b rotectedField;
private:
int m_nP 141f513b rivateField;
// P 141f513b UBLIC
class B : public A
public:
B()
~B()
void Work()
// P 141f513b ROTECTED
class C : protected A
public:
C()
~C()
void Work()
void main()
// BASE CLASS
class A
/*virtual*/ ~A()
;
/*virtual*/ void Work()
// DERIVED CLASS
class B : public A
~B()
;
void Work()
void main()
Which message will be displayed when you call pA->Work()?
a) when A::Work() is declared virtual
b) when A::Work() is declared non-virtual
c) when A::~A is declared virtual
d) when A::~A is declared non-virtual
// BASE CLASS
class A
~A()
;
void Work()
// BASE CLASS
class B
~B()
;
void Work()
// DERIVED CLASS
class C : public A
~C()
;
void Work()
// MULTIP 141f513b LE INHERITANCE
class D : public C, public B
~B()
;
void Work()
void main()
Which messages will be displayed on the console when you make an instance of D class and call D's Work function?
Create a class which implements an array of int. This class should contain only one function which get an item specified by an index.
Use the same class to manage an array of floats.
Use the same class to manage an array of chars.
#include <iostream>
using namespace std;
template <class T>
class Array
T m_t[size];
public:
Array() ;
T& operator[](int index)
return m_t[index];
}
~Array() ;
void main()
for (i = 0; i < 10; i++)
Using STL and the Array class defined above, define an array of strings and write its items to a file.
Note: don't use standard strings (char*) and files (FILE*)
#include <iostream>
#include <strstream>
#include <string>
#include <fstream>
using namespace std;
template <class T>
class Array
T m_t[size];
public:
Array() ;
T& operator[](int index)
return m_t[index];
}
~Array() ;
void main()
for (i = 0; i < 10; i++)
P 141f513b ut the above class in a namespace, and try to make the difference between why to use namespaces and why to not use namespaces.
#include <iostream>
#include <strstream>
#include <string>
#include <fstream>
using namespace std;
namespace ARRAY
T m_t[size];
public:
Array() ;
T& operator[](int index)
return m_t[index];
}
~Array() ;
class Array
void main()
for (i = 0; i < 10; i++)
[ Debugging ]
What is the purpose of the ASSERT macro?
ASSERT() is supposed to evaluate its parameter and, if this is zero, to break the execution. In release mode, ASSERT does nothing.
What is the purpose of the VERIFY macro?
VERIFY() runs exactly like ASSERT, but it runs in both debug and release modes.
What is the purpose of the TRACE macro?
TRACE() is the counterpart of printf(), except that it prints to the debug window. It also does nothing in release mode.
_ASSERT and _ASSERTE
The CRTDBG.H file defines those two macros for assertion checking. What is the difference between them?
_ASSERT: if the expression is evaluated to false (or zero), its result is the filename and the line of the assertion.
_ASSERTE is more powerful because it returns the filename and the line of the assertion, as well as the expression that turned out to be false. This may be enough to identify the problem without referring to the source code. However, the Debug version of your application will contain a string constant for each expression asserted using _ASSERTE. If you use many _ASSERTE macros, these string expressions take up a significant amount of memory. If that proves to be a problem, use _ASSERT to save memory.
#define _ASSERTE(expr) \
|