hi,
c++ is bei mir schon länger her, geht aber noch so halbwegs.

btw. der code hat zwar wenig sinn, aber das prinzip sollte dadurch klar sein:
Main.cpp:
PHP-Code:
#include "stdafx.h"
#include "stdafx.h"
#include <iostream>
#include <stack>
#include "TRStack.h"
int _tmain(int argc, _TCHAR* argv[])
{
TRStack* pExample = new TRStack(5);
TRStack* pExample2 = new TRStack(7);
bool empty = pExample->TRempty();
TRStack pResult = *pExample + *pExample2;
cout << pResult.testval;
return 0;
}
TRStack.h:
PHP-Code:
#pragma once
#include<iostream>
#include<stack>
using namespace std;
class TRStack
{
public:
// Varialbes
stack<double> Example;
int testval;
// functions
TRStack(int n);
bool TRempty(void);
TRStack& operator+(const TRStack& r);
public:
~TRStack(void);
};
TRStack.cpp:
PHP-Code:
#include "StdAfx.h"
#include "TRStack.h"
#include<iostream>
#include<stack>
using namespace std;
TRStack::TRStack(int n)
{
cout << "Stack initialisiert" << endl;
testval = n;
}
TRStack& TRStack::operator+ (const TRStack& r)
{
// do overloading as you like
// example
this->testval += r.testval;
return *this;
}
bool TRStack::TRempty(void)
{
return false;
}
TRStack::~TRStack(void)
{
}
blöde formatierung - es heißt natürlich, ohne Leerzeichen:
TRStack & TRStack :: operator + (const TRStack& r)
fg
hannes