C-plus-plus: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 4: | Zeile 4: | ||
* [[C-plus-plus-Scrambler]] | * [[C-plus-plus-Scrambler]] | ||
= Beispiel Klasse Complex = | = Klassen = | ||
== Beispiel Klasse Complex == | |||
<syntaxhighlight lang="c++"> | <syntaxhighlight lang="c++"> | ||
class Complex | class Complex | ||
Zeile 22: | Zeile 23: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Beispiel Interface == | |||
<syntaxhighlight lang="c++"> | |||
class Box { | |||
public: | |||
// pure virtual function | |||
virtual double getVolume() = 0; | |||
}; | |||
</syntaxhighlight> | |||
= Exception = | = Exception = | ||
<syntaxhighlight lang="c++"> | <syntaxhighlight lang="c++"> |
Version vom 6. Dezember 2022, 18:06 Uhr
Links
Klassen
Beispiel Klasse Complex
class Complex
{
public:
double _real;
double _imag;
public:
Complex(): _real(0), _imag(0) {}
Complex(double real, double imag): _real(real), _imag(imag) {}
Complex(const Complex &src): _real(src._real), _imag(src._imag) {}
Complex& operator =(const Complex& source){
_real = source._real;
_imag = source._imag;
return *this;
}
};
Beispiel Interface
class Box {
public:
// pure virtual function
virtual double getVolume() = 0;
};
Exception
class ReException {
public:
ReException(const char* message);
ReException(const char* message, const char* file, int line);
virtual ~ReException();
public:
ReException(const ReException& source): _message(source._message){};
ReException& operator =(const ReException& source){ _message = source._message; }
protected:
ReException();
public:
inline void setMessage(const char* message) {
if (m_message != NULL)
free((void *) m_message);
m_message = _strdup(message);
}
}
inline const char* getMessage() const {
return m_message;
}
protected:
const char* m_message;
};