Variante 1: öffentliche, statische Klassenmember
Eins.hpp
Code: Alles auswählen
class Eins {
    public:
        static int value;
        static int something(int a);
};Code: Alles auswählen
#include "Eins.hpp"
int Eins::value = 0;
int Eins::something(int a) {
    return a * a;
}Zwei.hpp
Code: Alles auswählen
struct Zwei {
    static int value;
    static int something(int a);
};Code: Alles auswählen
#include "Zwei.hpp"
int Zwei::value = 0;
int Zwei::something(int a) {
    return a * a;
}Drei.hpp
Code: Alles auswählen
namespace Drei {
    extern int value;
    int something(int a);
}Code: Alles auswählen
#include "Drei.hpp"
int Drei::value = 0;
int Drei::something(int a) {
    return a * a;
}Code: Alles auswählen
#include <iostream>
#include "Eins.hpp"
#include "Zwei.hpp"
#include "Drei.hpp"
int main() {
    Eins::value += Eins::something(5);
    std::cout << Eins::value << std::endl;
    Zwei::value += Zwei::something(5);
    std::cout << Zwei::value << std::endl;
    Drei::value += Drei::something(5);
    std::cout << Drei::value << std::endl;
}Möchte ich "interne" Daten dazunehmen (die für Außen nicht sichtbar sind), fällt die Namespace-Variante weg, richtig?
LG Glocke



