1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#ifndef KLIST_H
#define KLIST_H
#include "kNode.h"
#include "Thing.h"
class kList{
friend class Brain;
public:
kList();
~kList();
void add(char *); //add a node at the end of the list
bool remove(); //remove a node from the back of the list
bool isEmpty();
int getLength();
private:
kNode *firstNode;
kNode *lastNode;
kNode *getNewNode(char *);
};
kList::kList() : firstNode(0), lastNode(0){
}
kList::~kList(){
if (!isEmpty()){
std::cout<<"destroying all nodes in the list\n";
kNode *currentNode = firstNode;
kNode *tempNode;
while (currentNode != 0){
tempNode = currentNode;
currentNode = currentNode->nextNode;
delete tempNode;
}
}
std::cout<<"All Nodes were destroyed\n";
}
void kList::add(char *id){
kNode *newNode = getNewNode(id);
if (isEmpty()){ //if the list is empty
firstNode = lastNode = newNode;
}
else{ //if its not
lastNode->nextNode = newNode;
lastNode = newNode;
}
}
kNode *kList::getNewNode(char *id){
return new kNode(id);
}
bool kList::isEmpty(){
return firstNode == 0; //if the first pointer is = 0 (it doesnt point to anything
}
int kList::getLength(){
kNode *currentNode = firstNode;
if (!isEmpty()){
for (int counter = 1; currentNode->nextNode != 0; counter++){
if (currentNode = lastNode){
return counter;
}
}
}
else{
return 0;
}
}
#endif
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#ifndef KNODE_H
#define KNODE_H
#include "Thing.h"
#include "kList.h"
#include <string>
using namespace std;
class kNode{
friend class kList;
friend class Brain;
public:
kNode(char *);
char *getPropertiesListNode(); //returns the first pointer from the proporties list
char *getId(); //returns the ID of the Node (contains the thing class)
void addProperty(char *);
void setId(char *);
bool propertyExist( char *);
void addOperator(char *);
private:
Thing Data;
kNode *firstNode;
kNode *nextNode;
};
kNode::kNode(char *id) : firstNode(0), nextNode(0){
Data.setId(id); //creates a new thing object so with the ID and proporties that are passed through the function
}
char *kNode::getId() {
return Data.getId();
}
void kNode::addProperty(char *prop){
Data.addProperty(prop);
}
void kNode::addOperator(char *op){
Data.addOperator(op);
}
void kNode::setId(char *id){
Data.setId(id);
}
bool kNode::propertyExist(char *prop){
return Data.propertyExist(prop);
}
#endif
|
Error 1 error C2143: syntax error : missing ';' before '*' c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 22
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 22
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 22
Error 4 error C2143: syntax error : missing ';' before '*' c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 23
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 23
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 23
Error 7 error C2143: syntax error : missing ';' before '*' c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 24
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 24
Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 24
Error 11 error C2614: 'kList' : illegal member initialization: 'lastNode' is not a base or member c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 29
Error 12 error C2614: 'kList' : illegal member initialization: 'firstNode' is not a base or member c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 29
Error 13 error C2065: 'kNode' : undeclared identifier c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 39
Error 14 error C2065: 'currentNode' : undeclared identifier c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 39
Error 15 error C2065: 'firstNode' : undeclared identifier c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 39
Error 16 error C2065: 'kNode' : undeclared identifier c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 40
Error 17 error C2065: 'tempNode' : undeclared identifier c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 40
Error 18 error C2065: 'currentNode' : undeclared identifier c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 42
Error 19 error C1903: unable to recover from previous error(s); stopping compilation c:\documents and settings\brett\my documents\visual studio 2008\projects\jarvis stage1\jarvis stage1\klist.h 42
all errors occur in kList.h