Solved

Does not Compile

Posted on 2004-10-06
3
329 Views
Last Modified: 2008-02-01

#ifndef UTIL_H  
#define UTIL_H

#define NULL 0L

#define STDSCREEN 80        
#define DOWN 0                        
#define UP   1
#define END   0
#define START 1
#define FAIL    0
#define SUCCESS 1
#define MISS -1
#define HIT   1

enum Error_code{success,fail,range_error,underflow,overflow,fatal,
                not_present,duplicate_error,entry_inserted,entry_found,
                internal_error};

void clearScreen();                  
void clearTop();                      
void clearBelowTop();                
void goTop();                            
void topLine(const char * text = " "  );    
void bottomLine (char * text = " ");  
void hitAnyKey ();                  
void flushInput ();                  
void Warning(char *);                  
void Error(char *);                  
bool promptYesNo(char * prompt="");    
void EatWhiteSpace(void);              

#endif

// futil.cpp
   
#include <iostream>
#include <ctype.h>
#include <stdlib.h>
#include "util.h"
 
void clearScreen(void) {
 
  cout << "\033[2J";          
  cout << "\033[;f";          

}

void clearTop()

  {cout << "\033[0;0f" << "\033[0K";}

void clearBelowTop()
 
  {cout << "\033[1;0f" << "\033[1B" << "\033[J";}

void goTop()
 
  {cout << "\033[0;0f";}

void topLine(const char str[])
 
  {cout << "\033[0;0f" << "\033[0K" << str;}

void bottomLine (char * str)
 
  {cout << "\033[23;0Hf" << "\033[2K" << str;}

void hitAnyKey() {
   
   char ch;
   bottomLine ("Hit any key to continue...");
   cin.get(ch);
   clearScreen();

}

void flushInput() {
   
   char buff[81];
   if (cin)
      cin.getline(buff,80);  

}

void Warning(char *message){cerr << message;}

void Error(char *message) {
 
   cerr << message;
   exit(1);

}

void EatWhiteSpace() {
 
    char ch;
    do {
      cin.get(ch);
    }
    while(isspace(ch));

    if(ch != EOF)
      cin.putback(ch);
}

bool promptYesNo(char *c) {
 
   char ch;
   cout << c << " [y|n]?";
   do {
      cin.get(ch);  
      tolower(ch);
      } while (ch != 'y' && ch != 'n');
   return (ch == 'y');

}

// list.h
 
#ifndef LIST_H
#define LIST_H

#include<iostream>
#include "node.h"
#include "util.h"

typedef int pos;

template<class Input_data>
class List {

public:

  List();
  List(const List<Input_data> &copy);
  ~List();
  void operator=(const List<Input_data> &copy);
  void clear();
  bool empty() const;
  bool full() const;
  int size() const;
  void display() const;

 
  Error_code retrieve(const pos, Input_data &) const;
  Error_code replace(const pos, Input_data &) const;
  Error_code insert(const pos, Input_data &) const;
  Error_code remove(const pos, Input_data &) const;

protected:

  int count;
 
  Node<Input_data> *head;
  Node<Input_data> *set_pos(int pos) const;

};

template<class Input_data)
Node<Input_data> *List<Input_data>::set_pos(int pos) const {

  if(pos<1||pos>count)
    return NULL;
  Node<Input_data> *ind=head;
  for(int i=1; i<pos; i++)
    ind=ind->next;
  return next;

}

template<class Input_data>
List<Input_data>::List() {

  head=NULL;
  count=0;

}

template<class Input_data>
List<Input_data>::~List() {

  clear();

}

template<class Input_data>
List<Input_data>::List(const<Input_data> &valueList) {

  count=valueList.count;
  if(valueList.head==NULL)
    head=NULL;
  else {
    head=new Node<Input_data>(valueList.head->entry);

  Node<Input_data> *value=valueList.head->next;
  Node<Input_data> *copy=head;

    while(value != NULL) {
      copy->next=new Node<Input_data>(value->entry);
      value=value->next;
      copy=copy->next;

    }
  }
 
}

template<class Input_data>
void List<Input_data>::operator=(const List<Input_data> &copy){}

template<class Input_data>
void List<Input_data>::clear() {
 
  Node<Input_data> *ind=head;
  Node<Input_data> *sax_ptr;
  ind=head;
 
    while(ind!=NULL) {
      sax_ptr=ind;
      ind=ind->next;
      delete sax_ptr;
     
    }
    head=NULL;
    count=0;
   
}

template<class Input_data>
bool List<Input_data>::empty() const {
 
  return(head==NULL);
 
}

template<class Input_data>
bool List<Input_data>::full() const {
 
  Node<Input_data> *run=new Node<Input_data>();
    return(run==NULL);
   
}

template<class Input_data>
int List<Input_data>::size() const{ return count;}

template<class Input_data>
void List<Input_data>::display() const {
 
  Node<Input_data> *ind=head;
 
    while(ind!=NULL) {
      cout << ind->entry << " ";
      ind=ind->next;
     
    }
    cout << endl;
   
}

template<class Input_data>
Error_code List<Input_data>::retrieve(const pos p, const Input_data
                             &value)
{
  Node<Input_data> *ind=set_pos(p);
  if(ind==NULL)
    return range_error;
  value=ind->entry;
  return success;
 
}

template<class Input_data>
Error_code List<Input_data>::replace(const pos p, const Input_data
                            &value)
{
  Node<Input_data> *ind=set_pos(p);
  if(ind==NULL)
    return range_error;
  ind->entry=value;
  return success;
 
}

template<Input_data>
Error_code List<Input_data>::insert(const pos p, const Input_data
                           &value)
{
  if(full())
    return overflow;
    if(p<1||p>count+1)
      return range_error;
     
  Node<Input_data> *ind=head;
  Node<Input_data> *new_node=new Node<Input_data>(value);
    if(p==1) {
      new_node->next=head;
      head=new_node;
     
    }
    else {
      for(int i=1; i<p-1; i++)
      ind=ind->next;
      new_node->next=ind->next;
      ind->next=new_node;
      
    }
    count++;
    return success;
   
}

template<class Input_data>
Error_code List<Input_data>::remove(const pos p) {
 
  if(empty())
    return underflow;
    if(p<1||p>count)
      return range_error;
     
  Node<Input_data> *sax_ptr;
  Node<Input_data> *ind;
 
    if(p==1) {
      ind=head;
      head=head->next;
      delete ind;
     
    }
    else {
      sax_ptr=set_pos(p-1);
      ind=sax_ptr->next;
      sax_ptr->next=ind->next;
      delete ind;
     
    }
    count--;
    return success;
   
}

#endif  
   
//  node.h

#ifndef NODE_H
#define NODE_H

#include<iostream>

template<class Input_data>
class Node {

  public:

    Node();
    Node(const Input_data &);
    Input_data entry;
    Node<Input_data> *next;

};

template<class Input_data>
Node<Input_data>::Node() {

  entry=0;
  next=NULL;

}

template<class Input_data>
Node<Input_data>::Node(const Input_data &value) {

  entry=value;
  next=NULL;

}

#endif

/* filename: main.cpp
   programmer: Enrique De Los Santos
   project: hw4*/

#include<iostream>

#include "list.h"
#include "util.h"

void main() {

  int data;
  List<int>list_1;
  list_1.insert(0,1);
  list_1.insert(1,2);
  list_1.insert(2,3);
  list_1.insert(3,4);
  list_1.insert(4,5);
  list_1.retrieve(1, data);

  cout << endl;

    if(list_1.remove(9)==success)
      cout << "success";
    else
      cout << "range_error\n";


  list_1.remove(0);
  list_1.remove(2);
  list_1.remove(5);
  list_1.insert(2,2);
  list_1.insert(7,7);
  cout << "1st List: ";
  list_1.display();

  List<int>list_2(list_1)
  list_2.insert(2,2);
  cout << "2nd List: ";
  list_2.display();

  cout << "1st List: ";
  list_1.display();
  list<int> list_3=list_1;
  cout<< "3rd List: ";
  list_3.display();
  cout << endl;

void bubble_sort(list_2) {

    cout << "2nd List Sorted: ";
    list_2.display();
    cout << endl;

}

output:

[edeloss2@pegasus hw4]$ make veryclean
rm -f *.o
rm -f core
rm -f  main
[edeloss2@pegasus hw4]$ make
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9  -gall main.cpp
cxx: Error: list.h, line 45: identifier "Input_data" is undefined
Node<Input_data> *List<Input_data>::set_pos(int pos) const {
-----^
cxx: Error: list.h, line 45: identifier "Input_data" is undefined
Node<Input_data> *List<Input_data>::set_pos(int pos) const {
-----------------------^
cxx: Error: list.h, line 44: expected a "," or ">"
template<class Input_data)
-------------------------^
cxx: Error: list.h, line 45: expected a declaration
Node<Input_data> *List<Input_data>::set_pos(int pos) const {
-----------------------------------------------------------^
cxx: Error: list.h, line 45: expected a ";"
Node<Input_data> *List<Input_data>::set_pos(int pos) const {
-----------------------------------------------------------^
cxx: Warning: list.h, line 194: parsing restarts here after previous syntax
          error
    return success;
------------------^
cxx: Error: list.h, line 196: expected a declaration
}
^
cxx: Warning: list.h, line 222: parsing restarts here after previous syntax
          error
    count--;
-----------^
cxx: Error: list.h, line 223: expected a declaration
    return success;
----^
cxx: Error: list.h, line 225: expected a declaration
}
^
cxx: Warning: main.cpp, line 31: parsing restarts here after previous syntax
          error
  list_1.remove(5);
------------------^
cxx: Error: main.cpp, line 32: this declaration has no storage class or type
          specifier
  list_1.insert(2,2);
--^
cxx: Error: main.cpp, line 32: expected a ";"
  list_1.insert(2,2);
--------^
cxx: Error: main.cpp, line 33: this declaration has no storage class or type
          specifier
  list_1.insert(7,7);
--^
cxx: Error: main.cpp, line 33: declaration has already been defined by
          variable "list_1" (declared at line 32)
  list_1.insert(7,7);
--^
cxx: Error: main.cpp, line 33: expected a ";"
  list_1.insert(7,7);
--------^
cxx: Error: main.cpp, line 34: this declaration has no storage class or type
          specifier
  cout << "1st List: ";
--^
cxx: Error: main.cpp, line 34: declaration is incompatible with
          "ostream_withassign cout" (declared at line 846 of
          "/usr/include/cxx/iostream_impl.hxx")
  cout << "1st List: ";
--^
cxx: Error: main.cpp, line 34: expected a ";"
  cout << "1st List: ";
-------^
cxx: Error: main.cpp, line 35: this declaration has no storage class or type
          specifier
  list_1.display();
--^
cxx: Error: main.cpp, line 35: declaration has already been defined by
          variable "list_1" (declared at line 33)
  list_1.display();
--^
cxx: Error: main.cpp, line 35: expected a ";"
  list_1.display();
--------^
cxx: Error: main.cpp, line 37: no instance of constructor
          "List<Input_data>::List [with Input_data=int]" matches the argument
          list
            argument types are: (int)
  List<int>list_2(list_1)
------------------^
cxx: Error: main.cpp, line 38: expected a ";"
  list_2.insert(2,2);
--^
cxx: Error: main.cpp, line 39: this declaration has no storage class or type
          specifier
  cout << "2nd List: ";
--^
cxx: Error: main.cpp, line 39: declaration has already been defined by
          variable "cout" (declared at line 34)
  cout << "2nd List: ";
--^
cxx: Error: main.cpp, line 39: expected a ";"
  cout << "2nd List: ";
-------^
cxx: Error: main.cpp, line 40: this declaration has no storage class or type
          specifier
  list_2.display();
--^
cxx: Error: main.cpp, line 40: declaration has already been defined by
          variable "list_2" (declared at line 37)
  list_2.display();
--^
cxx: Error: main.cpp, line 40: expected a ";"
  list_2.display();
--------^
cxx: Error: main.cpp, line 42: this declaration has no storage class or type
          specifier
  cout << "1st List: ";
--^
cxx: Error: main.cpp, line 42: declaration has already been defined by
          variable "cout" (declared at line 39)
  cout << "1st List: ";
--^
cxx: Error: main.cpp, line 42: expected a ";"
  cout << "1st List: ";
-------^
cxx: Info: Error limit reached.
cxx: Info: 30 errors detected in the compilation of "main.cpp".
cxx: Info: Compilation terminated.
make: *** [main.o] Error 1


0
Comment
Question by:edelossantos
3 Comments
 
LVL 9

Assisted Solution

by:jhshukla
jhshukla earned 125 total points
ID: 12245709
>>> template<class Input_data)
--------------------------------------------^ This is your error! need > instead of )
silly, isn't it. don't waste your points for things like this. ask a question but put it at something like 50pts
0
 
LVL 3

Accepted Solution

by:
teratoma earned 125 total points
ID: 12245711
The error message:

cxx: Error: list.h, line 45: identifier "Input_data" is undefined

The cause:

template<class Input_data)
Node<Input_data> *List<Input_data>::set_pos(int pos) const {

this:

template<class Input_data)

should be this:

template<class Input_data>
0
 

Author Comment

by:edelossantos
ID: 12249925
Thank you to the both of you.  Del
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now