C++ Quick Review Flashcards

Terms Definitions
derived class methods can access what base class data?
public and protected variables only. private variables in base class can only be accessed via public/protected base class methods.
how do you prevent redefinitions?
#ifndef INCLUDED_FILENAME_H
#define INCLUDED_FILENAME_H
header file contents
#endif

in the header file
basic class derivation syntax?
class MySubClass : public MyBaseClass {
public:
MySubClass() : MyBaseClass();
protected:
}
what does virtual do?
Tells compiler to call subclass member function (C++ does not do polymorphism by default)
define a constant integer
const int x=0;
define a pointer with readonly access to an integer
const int * x=&roint;
int const * x=&roint;
define a constant pointer to an integer
int * const x=&myval; //behaves like a reference
declare a method that can't modify its object
void MyClass::member1(...) const;
declare an integer reference parameter, readonly
void myfunc(const int& para1);
declare a reference-to-const integer parameter
void myfunc(int const &para1);
use a template to declare a min function taking a T type
template<class T>
T min(T a, T b){
return a > b ? b : a;
}
assign a readonly pointer to a regular pointer
const char * xro = "hello";
char * x = const_cast<char *>(xro);
fix this constructor => const string val1ro; public: MyClass(const string& setval1ro); ...
use member initializer=>

MyClass(const string& setval1) : val1ro(setval1ro);
Using a readonly pointer to an object can you change the object by invoking a non-const method?
Yes. readonly pointers have shallow constness.
/ 14
Term:
Definition:
Definition:

Leave a Comment ({[ getComments().length ]})

Comments ({[ getComments().length ]})

{[comment.username]}

{[ comment.comment ]}

View All {[ getComments().length ]} Comments
Ask a homework question - tutors are online