Einzelnen Beitrag anzeigen
Alt 25.04.2006, 10:20   #4
Biri
Hero
 
Registriert seit: 04.09.2001
Beiträge: 894


Standard

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_TCHARargv[])
{
    
TRStackpExample = new TRStack(5); 
    
TRStackpExample2 = 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<doubleExample;
    
int testval;

    
// functions
    
TRStack(int n);    
    
bool TRempty(void);
    
TRStackoperator+(const TRStackr);
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;
}

TRStackTRStack::operator+ (const TRStackr

    
// 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
Biri ist offline   Mit Zitat antworten