PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : c++ meinet mein konstruktor geht net ;)



pfefferkeks
09-02-2005, 17:44
Hi,

habe folgendes fuer test zwecke geschrieben aber es geht net:
Makefile:



# Verzeichnisse festlegen
INC=./include
LIB=./lib

# Compiler festlegen C:gcc C++:g++
CC = g++

# Debuggen ja:-ggdb nein: leer lassen
DEBUG =

# Compile-Flags festlegen
CCFLAGS=${DEBUG} -Wall -I${INC} -Wno-deprecated

# Linker und Flags festlegen C:gcc C++:g++ oder ld als realer Linker
LD = ld
LDFLAGS=-L./lib

# Bibliotheksverwalter
AR=ar
ARFLAGS=rcv

.SUFFIXES: .cpp .o

# hier alle Projekt-Targets eintragen
all: clean container install testMain

# im folgenden die Projekt-Targets spezifizieren
container: container.o container.h container.cpp
${AR} ${ARFLAGS} libcontainer.a container.o

testMain: testMain.cpp
${CC} ${LDFLAGS} ${CCFLAGS} -o testMain testMain.cpp -lcontainer

# Loeschen aller Objektdateien
clean:
rm -f testMain
rm -f *.o
rm -f *.a
rm -f ./lib/*.a
rm -f ./include/*.h

# Kopieren aller Header und Bibliotheken
install: incl libe

incl:
cp *.h ${INC}

libe:
cp *.a ${LIB}

.cpp.o:
${CC} ${CCFLAGS} -c $< -o $@



container.h:



/*
* Container for Integer header file, it's coded in c++.
*
* name: container.h
* create: Feb-08-2005
*
* last modifi: Feb-9-2005
*
* @athour: Walkowski, Swen
*
* @version: 0.1
*
*/

#ifndef _CONTAINER_
#define _CONTAINER_

class Container {
public:
Container(); ///<Defaultkonstruktor

int begin (void); ///<first element of the container
int end (void); ///<last element of the container
int size (void); ///<Size of the Container

bool isEmpty (void); ///<true, if the Container is empty

void dumpForward (void); ///<Give values, starting with the first
void dumpBackward (void); ///<Give values, startin with the last

protected:
/**
* This structur defines an element of an duble interlinked list
*
* An element from the list implements a pointer to the next and
* the prev element. Also the element hast an integer value.
*/
struct element {
int value; ///<value of the element

element* next; ///<pointer of the next-element
element* prev; ///<pointer of the prev-element
};

element* first; ///<pointer of the first-element
element* last; ///<pointer of the last-element

int count; ///<number of the container
};

#endif /*_CONTAINER_*/


container.cpp:


/*
* Container for Integer, it's coded in c++.
*
* name: container.cpp
* create: Feb-09-2005
*
* last modifi: Feb-09-2005
*
* @athour: Walkowski, Swen
*
* @version: 0.1
*
*/

#include <iostream.h>
#include "container.h"

/**
* Defaultkonstruktor, initialise the values of the container element
* with standart values.
*/
Container::Container(): count(0), first(0), last(0) {
std::cout << std::endl << "Defaultkonstruktor Contaier() was starting.";
std::cout << std::endl << "Initialise count="<< Container::count;
std::cout << " first=" << Container::first << " last=";
std::cout << Container::last << std::endl;
};

/**
* @return : flase if the container isn't empty
* @return : true if the container is empty
*/
bool Container::isEmpty (void) {
if (0 != Container::count) {
return false;
}
else {
return true;
}
};


und testMain.cpp



/*
* Test main for the class container, list, deque and list,
* it's coded in c++.
*
* name: testMain.cpp
* create: Feb-09-2005
*
* last modifi: Feb-09-2005
*
* @athour: Walkowski, Swen
*
* @version: 0.1
*
*/

#include <iostream.h>
#include "container.h"

using namespace std;

int main (void) {
cout << "Container" << endl;
Container* conOne = new Container;

cout << "Is container empty?:";
if (conOne->isEmpty) {
cout << "yes" << endl;
}
else {
cout << "no" << endl;
}

delete conOne;

return 0;
}



fehlermeldung des compilers:
rm -f testMain
rm -f *.o
rm -f *.a
rm -f ./lib/*.a
rm -f ./include/*.h
g++ -Wall -I./include -Wno-deprecated -c container.cpp -o container.o
container.h: In constructor `Container::Container()':
container.h:48: Warnung: `Container::count' will be initialized after
container.h:45: Warnung: `Container::element*Container::first'
container.cpp:22: Warnung: when initialized here
ar rcv libcontainer.a container.o
a - container.o
cp *.h ./include
cp *.a ./lib
g++ -L./lib -Wall -I./include -Wno-deprecated -o testMain testMain.cpp -lcontainer
testMain.cpp: In function `int main()':
testMain.cpp:26: error: could not convert `conOne->Container::isEmpty' to `bool
'
make: *** [testMain] Fehler 1


ich verstehe einfach nicht warum er meint das container::count nich nicht initialized ist. mach ich doch im konstruktor. desweitern ist meine fkt. isEmpty doch bool was moechte er denn da convertieren?

danke fuer eure hilfe pfefferkeks

ps. sorry ich wuste nicht das es code tag gibt!

Joghurt
09-02-2005, 17:51
Du hast die Klammern vergessen:
if (conOne->isEmpty()) {
Und nutze bitte demnächst die code-Tags!

panzi
09-02-2005, 18:07
füg erstmal code tags ein, dann schau ich mir den code vieleicht an.
&#91;code&#93;...&#91;/code&#93;

locus vivendi
09-02-2005, 18:44
Achte auch auf die Warnmeldung. Im Moment ist die monierte Reihenfolge der Initialisierung zwar kein Fehler, aber eventuell könnte es einer werden.