The format of define preprocessor directives are:
#ifndef SIZE
#define SIZE 10
int hello[SIZE];
#endif
But when I look at the following code, there is no replacement for the preprocessor directives:
#ifndef CREDIT_CARD_H // Avoid repeated expansion
#define CREDIT_CARD_H
#include <string> // Provides string
#include <iostream> // Provides ostream
class CreditCard
{
public:
CreditCard(const std::string& no, // Constructor
const std::string& nm, int lim, double bal = 0);
// Accessor functions
std::string getNumber()const { return number; }
std::string getName() const { return name; }
double getBalance() const { return balance; }
int getLimit() const { return limit; }
bool chargeIt(double price); // Make a charge
void makePayment(double payment); // Make a payment
private: // Private member data
std::string number; // Credit card number
std::string name; // Card owner's name
int limit; // Credit limit
double balance; // Credit card balance
};
std::ostream& operator<<(std::ostream& out, const CreditCard& c);
#endif
What does this mean?
You can say
#define FOO, which means that#ifdef FOOwill be true, butFOOdoesn’t have any replacement text. This is useful precisely for conditional checks like the include guards.It can also be useful for platform-specific extensions, which you want to be empty in the general case: