Cheng Mo said:
Hi,
I am new to C++.
In Java, it is possible to define one class to be "final" so no other
class can inherit it.
I am wondering whether or not there is some mechanism in C++ do the same
job. Besides putting all constructors privte, any other solution?
// put this in header file:
// header_file.h
// -----------------------------
#ifndef HEADER_FILE_H
#define HEADER_FILE_H
class BaseOfFinalClass{
public:
// ...some interface functions eg
virtual void function1()=0;
virtual ~BaseOfFinalClass(){}
};
BaseOfFinalClass* makeFinalClass();
#endif
// ------------------------------
// put your final class in implementation file:
// implementation_file.cpp
// ------------------------
#include "header_file.h"
class FinalClass: public BaseOfFinalClass{
public:
// ... implementation functions
virtual void function1(){ /* ... */ }
};
BaseOfFinalClass* makeFinalClass()
{
return new FinalClass;
}
// ------------------------
Greetings, Bane.