illegal pure syntax

This is a discussion on illegal pure syntax within the C++ Programming forums, part of the General Programming Boards category; Hey, I am trying to create a capacity for my array in the public section of my class and it ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    81

    illegal pure syntax

    Hey, I am trying to create a capacity for my array in the public section of my class and it keeps giving me the same error "illegal pure syntax, must be '= 0' ". Here is my header code. The problem is apparently under the public section.

    Code:
    #include <iostream>
    using namespace std;
    
    class List
    {
    public:
    
    typedef int VALUE_TYPE;
    const int CAPACITY = 30;
    VALUE_TYPE array[CAPACITY];
    
    List(); //constructor
    List(List& x); //copy constructor
    //void destroy();
    //void assign();
    void remove();  //destroy operation
    void first(); //first operation
    void next(); //next operation
    void prev(); //previous operation
    void Makecurrent(int x); //makecurrent operation
    VALUE_TYPE current(); //shows current position
    VALUE_TYPE examine(); //examine operation
    void replace(VALUE_TYPE v); //replace operation
    VALUE_TYPE insertafter(VALUE_TYPE v); //insert after operation
    VALUE_TYPE insertbefore(VALUE_TYPE v); //insert before operation
    VALUE_TYPE size(); //Count operation
    
    friend ostream & operator<<(ostream& out, List x)
    {
    for(int i=0;i<CAPACITY;i++)
    out << x.array[i] << " ";
    }
    
    friend ostream & operator+(List x, List y)
    {
    
    for(int i=0;i<CAPACITY;i++)
    x.array[i] + y.array[i];
    }
    
    private:
    VALUE_TYPE pos;
    VALUE_TYPE used;
    VALUE_TYPE array[CAPACITY];
    
    };
    List::List()
    {
    pos=0;
    used=0;
    for(int i=0;i<CAPACITY;i++)
    	   array[i]=0;
    }
    List::List(List& x)
    {
    pos=x.pos;
    used=x.used;
    for(int i=0;i<CAPACITY;i++)
    	   array[i]=x.array[i];
    }
    void List::remove()
    {
    	VALUE_TYPE i;
    	if(used!=0 && used<CAPACITY)
    	{
    		i=pos;
    		while(i<=used && i<CAPACITY)
    		{
    		array[i]=array[i+1];
    		i++;
    		}
    	//	if(pos > used)
    		//	pos=used;
    	}
    
    }
    void List::first()
    {
    pos=array[0];
    }
    
    void List::next()
    {
    while(pos < used && pos >= 0)
    pos++;
    }
    
    void List::prev()
    {
    while(pos < used && pos >=0)
    pos--;
    }
    
    List::Makecurrent(int x)
    {
    	pos=x;
    if((pos > used) && (pos < 0))
       if(pos>used)
       {pos=used;}
       if(pos<0)
       {pos=0;}
    }
    
    List::VALUE_TYPE List::current()
    {
    if((pos <= used) && (pos > 0))
       {
          return pos;
       }
       else
       {
          return 0;
       }
    }
    
    VALUE_TYPE List::examine()
    {
    	VALUE_TYPE x,i;
    	i=pos;
    	x=array[i];
    return x;
    }
    
    void List::replace(VALUE_TYPE v)
    {
    	VALUE_TYPE x;
    
    	array[x]=v;
    
    }
    VALUE_TYPE List::insertafter(VALUE_TYPE v)
    {
    	
    /*if(used>CAPACITY)
    	return 0;
    for(int i=used;i>pos;i--)
    	mylist[i+1]=mylist[i];
    	pos++;
    	mylist[pos+1]=v;
    	used++;
    	return 1;
    	*/
    	return v;
    		
    }
    VALUE_TYPE List::insertbefore(VALUE_TYPE v)
    {
    	return v;
    }
    VALUE_TYPE List::size()
    {
    return used;
    
    }
    thanks

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    28
    Code:
    #include <iostream>
    using namespace std;
    
    const int CAPACITY=30;
    
    class List
    {
    public:
    
      typedef int VALUE_TYPE;
    
      //  VALUE_TYPE array[CAPACITY];
    
      List(); //constructor
      List(List& x); //copy constructor
      //void destroy();
      //void assign();
      void remove();  //destroy operation
      void first(); //first operation
      void next(); //next operation
      void prev(); //previous operation
      void Makecurrent(int x); //makecurrent operation
      VALUE_TYPE current(); //shows current position
      VALUE_TYPE examine(); //examine operation
      void replace(VALUE_TYPE v); //replace operation
      VALUE_TYPE insertafter(VALUE_TYPE v); //insert after operation
      VALUE_TYPE insertbefore(VALUE_TYPE v); //insert before operation
      VALUE_TYPE size(); //Count operation
    
      friend ostream & operator<<(ostream& out, List x)
      {
        for(int i=0;i<CAPACITY;i++)
          out << x.array[i] << " ";
      }
    
      friend ostream & operator+(List x, List y)
      {
    
        for(int i=0;i<CAPACITY;i++)
          x.array[i] + y.array[i];
      }
    
    private:
      VALUE_TYPE pos;
      VALUE_TYPE used;
      VALUE_TYPE array[CAPACITY];
    
    };
    List::List()
    {
      pos=0;
      used=0;
      for(int i=0;i<CAPACITY;i++)
        array[i]=0;
    }
    List::List(List& x)
    {
      pos=x.pos;
      used=x.used;
      for(int i=0;i<CAPACITY;i++)
        array[i]=x.array[i];
    }
    void List::remove()
    {
      VALUE_TYPE i;
      if(used!=0 && used<CAPACITY)
        {
          i=pos;
          while(i<=used && i<CAPACITY)
    	{
    	  array[i]=array[i+1];
    	  i++;
    	}
          //	if(pos > used)
          //	pos=used;
        }
    
    }
    void List::first()
    {
      pos=array[0];
    }
    
    void List::next()
    {
      while(pos < used && pos >= 0)
        pos++;
    }
    
    void List::prev()
    {
      while(pos < used && pos >=0)
        pos--;
    }
    
    void List::Makecurrent(int x)
    {
      pos=x;
      if((pos > used) && (pos < 0))
        if(pos>used)
          {pos=used;}
      if(pos<0)
        {pos=0;}
    }
    
    List::VALUE_TYPE List::current()
    {
      if((pos <= used) && (pos > 0))
        {
          return pos;
        }
      else
        {
          return 0;
        }
    }
    
    List::VALUE_TYPE List::examine()
    {
      VALUE_TYPE x,i;
      i=pos;
      x=array[i];
      return x;
    }
    
    void List::replace(VALUE_TYPE v)
    {
      VALUE_TYPE x;
    
      array[x]=v;
    
    }
    
    List::VALUE_TYPE List::insertafter(VALUE_TYPE v)
    {
    	
      /*if(used>CAPACITY)
        return 0;
        for(int i=used;i>pos;i--)
        mylist[i+1]=mylist[i];
        pos++;
        mylist[pos+1]=v;
        used++;
        return 1;
      */
      return v;
    		
    }
    List::VALUE_TYPE List::insertbefore(VALUE_TYPE v)
    {
      return v;
    }
    List::VALUE_TYPE List::size()
    {
      return used;
    }
    Try this code...
    Try to declare constants as global as ISO C++ forbids initialization of member valiable while declaration.

    You have declared VALUE_TYPE array[CAPACITY] both in public and private section. Uncomment the one you want.

    In the function defination you should not specify return type as VALUE_TYPE, rather use List::VALUE_TYPE

    Signature and defination of Makecurrent() was different...

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    81
    Thanks for your help. I compiled it with the changes and I recieved a compilation error in Visual C++ "INTERNAL COMPILER ERROR" it says its where I overloaded the + operator. Although, I get a different error in Gcc "`CAPACITY' was not declared in this scope" in the private section where the array is declared..

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    81
    dammit, i think I just made a typo and thats what screwed it up.. sorry.. Thanks again

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    81

    Another Problem

    I am having a problem with overloading the + and the = operator. I keep getting this error in Gcc:
    Code:
    `void operator=(const List&)' must be a nonstatic member
       function
    listhead.h:52: `void operator=(const List&)' must take exactly two arguments
    Here is my code:

    Code:
    #include <iostream>
    
    using namespace std;
    
    
    class List
    {
    public:
    
    typedef int VALUE_TYPE;
    //VALUE_TYPE array[CAPACITY];
    static const int CAPACITY=30;
    
    List(); //constructor
    List(List& x); //copy constructor
    //void destroy();
    //void assign();
    void remove();  //destroy operation
    void first(); //first operation
    void next(); //next operation
    void prev(); //previous operation
    void Makecurrent(int x); //makecurrent operation
    VALUE_TYPE current(); //shows current position
    VALUE_TYPE examine(); //examine operation
    void replace(VALUE_TYPE v); //replace operation
    VALUE_TYPE insertafter(VALUE_TYPE v); //insert after operation
    VALUE_TYPE insertbefore(VALUE_TYPE v); //insert before operation
    VALUE_TYPE size(); //Count operation
    
    //Operator overloads
    // << operator
    friend ostream & operator<<(ostream& out, List x)
    {
    for(int i=0;i<CAPACITY;i++)
    out << x.array[i] << " ";
    }
    //+ operator
    void friend operator+(List x , List y)
    //List result;
    for(int i=0;i<CAPACITY;i++)
    {
    x.array[i] + y.array[i];
    }
    //return result;
    }
    
    void friend operator=(const List& z)
    {
    if(this == &z)
    return;
    List::pos=z.pos;
    List::used=z.used;
    for(int i=0;i<CAPACITY;i++)
    {
    List::array[i]=z.array[i];
    }
    }
    //== operator
    int friend operator==(List& x, List& y)
    {
    for(int i=0;i<CAPACITY;i++)
    {
    if(x.array[i]==y.array[i])
    return 1;
    else
    return 0;
    }
    }
    
    
    private:
    
    VALUE_TYPE pos;
    VALUE_TYPE used;
    VALUE_TYPE array[CAPACITY];
    };
    Thanks

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    28
    you missed the starting parenthesis in the overloaded + operator defination

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    81
    jesus, thats 2 mistakes that could have been easily avoided. I'm still get some errors though. I do not believe they are typos either.

    anyway, I am still getting errors on the + operator overlaod.

    Thanks again for the help

  8. #8
    Registered User
    Join Date
    Oct 2003
    Posts
    28
    Is it your requirement to use friend function? Else you can use this code...

    Code:
    #include <iostream>
    
    using namespace std;
    
    
    class List
    {
    public:
    
      typedef int VALUE_TYPE;
      //VALUE_TYPE array[CAPACITY];
      static const int CAPACITY=30;
    
      List(); //constructor
      List(List& x); //copy constructor
      //void destroy();
      //void assign();
      void remove();  //destroy operation
      void first(); //first operation
      void next(); //next operation
      void prev(); //previous operation
      void Makecurrent(int x); //makecurrent operation
      VALUE_TYPE current(); //shows current position
      VALUE_TYPE examine(); //examine operation
      void replace(VALUE_TYPE v); //replace operation
      VALUE_TYPE insertafter(VALUE_TYPE v); //insert after operation
      VALUE_TYPE insertbefore(VALUE_TYPE v); //insert before operation
      VALUE_TYPE size(); //Count operation
    
    
      VALUE_TYPE getPos()
      {
        return pos;
      }
    
      VALUE_TYPE setPos(VALUE_TYPE val)
      {
        pos = val;
      }
    
      VALUE_TYPE getUsed()
      {
        return used;
      }
    
      VALUE_TYPE setUsed(VALUE_TYPE val)
      {
        used = val;
      }
    
      VALUE_TYPE getArrayValue(int index)
      {
        return array[index];
      }
    
      VALUE_TYPE setArrayValue(int index, int val)
      {
        array[index] = val;
      }
    
      List operator +(List x);
      List operator =(List x);
      int operator ==(List x);
    
      //Operator overloads
      // << operator
      friend ostream & operator <<(ostream& out, const List x);
      /*
        friend List operator +(const List x, const List y);
        friend void operator =(List x, const List z);
        friend int operator ==(List& x, List& y);
      */
    
    private:
    
      VALUE_TYPE pos;
      VALUE_TYPE used;
      VALUE_TYPE array[CAPACITY];
    
    };
    
    ostream & operator <<(ostream& out, const List x)
    {
      for(int i=0;i<List::CAPACITY;i++)
        out << x.array[i] << " ";
      return out;
    }
    
    //+ operator
    List List::operator +(List x)
    {
      List result;
      result.setPos(x.getPos());
      result.setUsed(x.getUsed());
    
      for(int i=0;i<x.CAPACITY;i++)
        {
          result.setArrayValue(i, (array[i] + x.getArrayValue(i)) );
        }
      return result;
    }
    
    List List::operator =(List x)
    {
      List result;
      result.setPos(x.getPos());
      result.setUsed(x.getUsed());
    
      for(int i=0;i<x.CAPACITY;i++)
        {
          result.setArrayValue(i, x.getArrayValue(i) );
        }
      return result;
    }
    
    //== operator
    int List::operator==(List y)
    {
      int flag = 1;
    
      for(int i=0;i<y.CAPACITY;i++)
        {
          if(array[i] != y.getArrayValue(i))
    	{
    	  flag = 0;
    	  break;
    	}
        }
    
      return flag;
    }

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    81
    No, its not a requirement. But now the code is giving me errors about the variable CAPACITY... It says its not a member of the class, which it isn't... IT'S GLOBAL!! ugh... I will keep on working on it. Again, any help would be appreciated.

    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 09:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21