TE
TE
Crymes
Guest
AW: Problem mit den Funktionen bei C++
ja, eine .net (c++) mit Buttens, list boxen usw....
ja, eine .net (c++) mit Buttens, list boxen usw....
Es war halt in meinen Augen nur nicht klar für Crymes.
Da hast du Recht! Hab ich ja jetzt auch geschrieben, war was ungeschickt formuliert ^^Es war halt in meinen Augen nur nicht klar für Crymes.
Da ist was dran. Ich glaub der VS Klassenassistent macht das auch so (wenn man ihn denn nutzen möchte). Der macht aber auch nen paar andere Sachen:Ich glaub der gcc wirft da keinen Fehler, bin mir aber ganz ehrlich da auch nicht 100% sicher. Man kann so halt auf jeden Fall klar zwischen überladenen Funktionen unterscheiden, wenn man das void dazu nimmt.
Ich finds halt sauberer, wenn man Funktionen ohne Parameter das void als Parameter mit gibt![]()
class Blubb
{
public:
Blubb(void);
~Blubb(void);
private:
int m_var1;
int m_var2;
int m_var3;
};
// Vom VS Klassenassistenten generierte Initialsierungsliste
Blubb::Blubb(void)
: m_var1(0)
, m_var2(0)
, m_var3(0)
{
}


/*
* Copyright (c) 2002-2005 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Ron Dreslinski
* Ali Saidi
*/
/**
* @file
* Declaration of a bus object.
*/
#ifndef __MEM_BUS_HH__
#define __MEM_BUS_HH__
#include <list>
#include <set>
#include <string>
#include "base/hashmap.hh"
#include "base/range.hh"
#include "base/range_map.hh"
#include "base/types.hh"
#include "mem/mem_object.hh"
#include "mem/packet.hh"
#include "mem/port.hh"
#include "mem/request.hh"
#include "params/Bus.hh"
#include "sim/eventq.hh"
class Bus : public MemObject
{
/** Declaration of the buses port type, one will be instantiated for each
of the interfaces connecting to the bus. */
class BusPort : public Port
{
bool _onRetryList;
/** A pointer to the bus to which this port belongs. */
Bus *bus;
/** A id to keep track of the intercafe ID this port is connected to. */
int id;
public:
/** Constructor for the BusPort.*/
BusPort(const std::string &_name, Bus *_bus, int _id)
: Port(_name, _bus), _onRetryList(false), bus(_bus), id(_id)
{ }
bool onRetryList()
{ return _onRetryList; }
void onRetryList(bool newVal)
{ _onRetryList = newVal; }
int getId() { return id; }
protected:
/** When reciving a timing request from the peer port (at id),
pass it to the bus. */
virtual bool recvTiming(PacketPtr pkt)
{ pkt->setSrc(id); return bus->recvTiming(pkt); }
/** When reciving a Atomic requestfrom the peer port (at id),
pass it to the bus. */
virtual Tick recvAtomic(PacketPtr pkt)
{ pkt->setSrc(id); return bus->recvAtomic(pkt); }
/** When reciving a Functional requestfrom the peer port (at id),
pass it to the bus. */
virtual void recvFunctional(PacketPtr pkt)
{ pkt->setSrc(id); bus->recvFunctional(pkt); }
/** When reciving a status changefrom the peer port (at id),
pass it to the bus. */
virtual void recvStatusChange(Status status)
{ bus->recvStatusChange(status, id); }
/** When reciving a retry from the peer port (at id),
pass it to the bus. */
virtual void recvRetry()
{ bus->recvRetry(id); }
// This should return all the 'owned' addresses that are
// downstream from this bus, yes? That is, the union of all
// the 'owned' address ranges of all the other interfaces on
// this bus...
virtual void getDeviceAddressRanges(AddrRangeList &resp,
bool &snoop)
{ bus->addressRanges(resp, snoop, id); }
// Ask the bus to ask everyone on the bus what their block size is and
// take the max of it. This might need to be changed a bit if we ever
// support multiple block sizes.
virtual unsigned deviceBlockSize() const
{ return bus->findBlockSize(id); }
};
class BusFreeEvent : public Event
{
Bus * bus;
public:
BusFreeEvent(Bus * _bus);
void process();
const char *description() const;
};
/** a globally unique id for this bus. */
[B][COLOR=red] int busId;
/** the clock speed for the bus */
int clock;
/** cycles of overhead per transaction */
int headerCycles;
/** the width of the bus in bytes */
int width;[/B]
/** the next tick at which the bus will be idle */
Tick tickNextIdle;
Event * drainEvent;
usw....
/*
* Copyright (c) 2006 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Ali Saidi
*/
/**
* @file
* Definition of a bus object.
*/
#include <algorithm>
#include <limits>
#include "base/misc.hh"
#include "base/trace.hh"
#include "debug/Bus.hh"
#include "debug/BusAddrRanges.hh"
#include "debug/MMU.hh"
#include "mem/bus.hh"
Bus::Bus(const BusParams *p)
: MemObject(p),[B][COLOR=red] busId(p->bus_id), clock(p->clock),
headerCycles(p->header_cycles), width(p->width)[/B], tickNextIdle(0),
drainEvent(NULL), busIdle(this), inRetry(false), maxId(0),
defaultPort(NULL), funcPort(NULL), funcPortId(-4),
useDefaultRange(p->use_default_range), defaultBlockSize(p->block_size),
cachedBlockSize(0), cachedBlockSizeValid(false)
{
//width, clock period, and header cycles must be positive
if (width <= 0)
fatal("Bus width must be positive\n");
if (clock <= 0)
fatal("Bus clock period must be positive\n");
if (headerCycles <= 0)
fatal("Number of header cycles must be positive\n");
clearBusCache();
clearPortCache();
}
usw...
Da wirds dann SEHR interessant, den Code zu verstehen bei, was warens?, 250.000-500.000 Zeilen Code 
Dann darf das gar nicht funktionieren, da die Funktion ja als void Funktion geklariert ist, also ohne Rückgabewert. Eigentlich sollte das eine Fehlermeldung geben.
Genau wies einen Compilererror gibt, wenn man die Fuktion nicht void macht, sondern z.B. int und dann etwas anderszurück gibt als einen int, oder gar nichts zurück gibt.
). Ich hätte es halt eher so formatiert:Blubb::Blubb(void) :
m_var1(0),
m_var2(0),
m_var3(0)
{
}


Jetzt ernst gemeint. Ich weiß auch nicht jedes Detail, und hatte vorher damit recht wenig zu tun.
Naja, jedenfalls ist das ein typisches Beispiel für die Verwendung einer Initialisierungsliste.
Natürlich.Kannste eventuell noch was dazu sagen, warum man das mit variablen_name(irgendwas) macht, und was das bedeutet?
class Blubb
{
public:
Blubb(void);
~Blubb(void);
private:
int m_var1;
};
// "Klassisch" im Konstruktor
Blubb::Blubb(void)
{
m_var1 = 0;
}
// Initialisierungsliste
Blubb::Blubb(void) :
m_var1(0)
{
}
class Blubb
{
public:
Blubb(void);
~Blubb(void);
private:
const int m_var1; // die ist nun const!
};
Blubb::Blubb(void)
{
m_var1 = 0; // oops, m_var1 ist const :(
}
Blubb::Blubb(void) :
m_var1(0)
{
// so ist das ok, m_var1 hat jetzt den Wert 0
}
class A
{
public:
A(int param) :
m_param(param)
{
// hier ginge auch m_param = param!
}
~A(void)
{
}
private:
int m_param; // nicht const
};
class B
{
public:
B(void) :
m_a(1337) // hier wird der Konstruktor von A mit param = 1337 aufgerufen
{
// m_a(1337) geht nicht, da m_a const ist!
}
~B(void)
{
}
private:
const A m_a; // const
};
class Blubb
{
public:
Blubb(void);
~Blubb(void);
private:
std::string m_text;
};
Blubb::Blubb(void)
{
m_text = "Hallo, Welt!";
}
Blubb::Blubb(void) :
m_text("Hallo, Welt!")
{
}