Hi everyone...
I am currently doing the assignment about linked list. Here are some details information about what I am doing..
This program is C++ and should run on Visual Studio 2010.
And it contains three file, two datastructure header and one main cpp file.
This program is trying to arrange and show some sports records. The main program which contain the functions such as reading the result text file(each result text file contain several records of athletes), removing a file, arranging the totalresult and printing it out. And the main program is already given and I cannot overwrite it.
But when I finished and try to build the solution and run it, I am not able to run the program and it give me somethings like these...
warning C4172: returning address of local variable or temporary
error C2248: 'Datastructure1::Datastructure1' : cannot access private member declared in class 'Datastructure1'
see declaration of 'Datastructure1::Datastructure1'
see declaration of 'Datastructure1'
This diagnostic occurred in the compiler generated function 'Result::Result(const Result &)'
And I have tried to comment each function part of the header file and see if can run or not. But I still fail to do so.
Here are my codes...
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
|
#ifndef DATASTRUCTURE1_H
#define DATASTRUCTURE1_H
class Datastructure1 {
public:
Datastructure1( );
~Datastructure1( );
int size( ){
int i=0;
while(result[i]!= NULL){
i++;
}
return i;
}
bool add( int new_elem ){
for(int i=0;i<size();i++){
if(result[i]==NULL){
result[i] = new_elem;
return true;
}
}
return false;
}
int& operator []( int index ){
if(index>0 && index<(size()+1) ){
return result[index-1];
}
int a =0;
return (int &)a;
}
private:
int result[20];
// copying forbidden
Datastructure1(const Datastructure1&);
// no assignment
Datastructure1& operator=(const Datastructure1&);
};
#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 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
|
#ifndef DATASTRUCTURE2_H
#define DATASTRUCTURE2_H
#include "datastructure1.h"
using namespace std;
struct Result {
string name;
int totalresult;
Datastructure1 results;
Result *next;
};
class Datastructure2 {
public:
Datastructure2( );
~Datastructure2( );
int size( ){
int count=0;
Result* p = head;
while (p != NULL)
{
++count;
p = p->next;
}
return count;
}
bool add( Result* new_r, int index ){
Result *temp;
temp = head;
for(int c=1; c<(index-1); c++){
temp = temp->next;
}
if(temp->next!=NULL){
Result *temp2;
temp2=temp->next;
temp->next = new_r;
temp->next->next=temp2;
return true;
}else if(temp->next==NULL){
temp->next = new_r;
return true;
}else{return false;}
}
Result& operator[]( int index ){
int i;
Result *currPtr;
currPtr = head;
for(i = 1; i < index; i++){
currPtr = currPtr->next;
}
return *currPtr;
}
void remove( int index ){
int i;
Result *currPtr;
currPtr = head;
for(i = 1; i < index; i++){
currPtr = currPtr->next;
}
currPtr->next = currPtr->next->next;
}
void removeAll( ){
Result* temp1 = head;
while(temp1!=NULL)
{
head->next = temp1->next;
temp1->next = NULL;
delete(temp1);
temp1 = head->next;
}
}
private:
Result *head;
Result *tail;
// copying forbidden
Datastructure2(const Datastructure2&);
// no assignment
Datastructure2& operator=(const Datastructure2&);
};
#endif
|
There are two header files and look quite long. They are all some linked list functions . I have read and learn linked list data structure before I complete this programs. However, when I complete the functions required, the function cannot be compile....
Please help me and I have worked on this for whole weeks already..
thank you again