Need help with function calls

This is a discussion on Need help with function calls within the C++ Programming forums, part of the General Programming Boards category; Ok, so after about 2 hours of searching and beating my head against the wall I decided to just ask. ...

  1. #1
    Sum Dum Guy
    Join Date
    Jun 2004
    Posts
    7

    Need help with function calls

    Ok, so after about 2 hours of searching and beating my head against the wall I decided to just ask. I am having problem with a program I am trying to write, I have 2 classes, a double linked list class to hold each digit for large numbers. And a big int class which uses the list class to perform arithmetic on the large numbers. Anyway, I am having trouble using some of my functions in the DList class in any of the functions in the Big Int class.
    Specifically with the line
    Code:
    int size = list.size;
    I keep getting the error aggregate value used where an integer was expected.
    I know it is not a problem with my size function in the list class as it works perfectly when called from main, it just has this problem when called from the other class.
    I have also posted the code where this call is used and the header. Any and all help would be greatly appreciated
    Code:
    class BigInt : public DList
    {
      public:
        BigInt();
        ~BigInt();
        //BigInt toBigInt(DList list);
        void toBinary(DList list);
        //void toDecimal();
    
      private:
        DList binarylist();
        DList intlist();
    };
    Code:
    void BigInt::toBinary(DList list)
    {
      int temp;
      int size = list.size;
      for(int i=0, y;i<size;i++)
      {
        y = 8;
        temp = list.at(i);
        for(int x=0;x<4;x++)
        {
          if(temp >= y)
          {
            temp -= y;
            binarylist.at(i+x) = 1;
          }
          y /= 2;
        }
      }
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >int size = list.size;
    >I know it is not a problem with my size function
    You've answered your own question, albeit in a subtle way. You forgot the function call operator.
    Code:
    int size = list.size();
    My best code is written with the delete key.

  3. #3
    Sum Dum Guy
    Join Date
    Jun 2004
    Posts
    7
    oh crap.

    Thanks

    Good thing my first post made me look smrt, I mean smart.

  4. #4
    Sum Dum Guy
    Join Date
    Jun 2004
    Posts
    7
    alright then, one more quick question, I changed the function to look like this
    Code:
    void BigInt::toBinary(DList list)
    {
      int temp;
      int size = list.size();
      for(int i=0, compare;i<size;i++)
      {
        compare = 8;
        temp = list.at(i);
        for(int x=0;x<4;x++)
        {
          if(temp >= compare)
          {
            temp -= compare;
            binarylist.pushTail(1);
          }
          else
            binarylist.pushTail(0);
          compare /= 2;
        }
      }
    }
    but am having problems with
    Code:
    binarylist.pushTail(1);
    and
    Code:
    binarylist.pushTail(0);
    I am getting an error saying
    sorry, not implemented: 'overload not supported by dump_expr
    request for member `pushTail' in `{error}', which is of non-aggregate type `{unknown type}'

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Have you implemented pushTail? Your error messages are strangely unhelpful, post the class declaration and definitions (stripped down but still with the same error preferably).
    My best code is written with the delete key.

  6. #6
    Sum Dum Guy
    Join Date
    Jun 2004
    Posts
    7
    Code:
    class DList
    {
      public:
       DList();
       ~DList();
       void pushHead(int val);
       void pushTail(int val);
       void popHead();
       void popTail();
       int at(int point);
       int atTail();
       int size();
       void Print();
       void toList(char array[]);
      private:
        NodePtr Head;
        NodePtr Tail;
    };
    Code:
    void DList::pushTail(int val)
    {
      NodePtr temp;
      temp = new Node;
    
      temp->value = val;
      if(Head == NULL)
      {
        Tail = temp;
        Head = temp;
        Head->next = NULL;
        Head->previous = NULL;
        return;
      }
      temp->next = NULL;
      temp->previous = Tail;
      Tail->next = temp;
      Tail = temp;
    }
    I don't know why it isn't working, it works fine when called from main, just not when called from the class Big Int
    Last edited by phats; 06-06-2004 at 07:18 PM. Reason: messed up code in code tag

  7. #7
    Sum Dum Guy
    Join Date
    Jun 2004
    Posts
    7
    I suppose I should add that I am using Dev-C++ version 4. I did update to the newer beta version but found the error messages were even less helpful than in this version so I switched back.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    I'm going to need something that I can compile. Otherwise we'll be stuck playing 20 questions, and that gets old fast.
    My best code is written with the delete key.

  9. #9
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Code:
    class BigInt : public DList
    {
      public:
        BigInt();
        ~BigInt();
        //BigInt toBigInt(DList list);
        void toBinary(DList list);
        //void toDecimal();
    
      private:
        DList binarylist();
        DList intlist();
    };
    You declared binarylist as a function above (in bold).
    Code:
    void BigInt::toBinary(DList list)
    {
      int temp;
      int size = list.size();
      for(int i=0, compare;i<size;i++)
      {
        compare = 8;
        temp = list.at(i);
        for(int x=0;x<4;x++)
        {
          if(temp >= compare)
          {
            temp -= compare;
            binarylist.pushTail(1);
          }
          else
            binarylist.pushTail(0);
          compare /= 2;
        }
      }
    }
    But you use it as an object here. I assume those are supposed to be member variables, not functions.

    PS. If they are member variables then that also makes me wonder why BigInt derives from DList and also contains two DLists.

  10. #10
    Sum Dum Guy
    Join Date
    Jun 2004
    Posts
    7
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <vector>
    #include <string>
    
    using namespace std;
    
    //------------------------------------------------------------------------------
    //Double Linked List class definitions
    //------------------------------------------------------------------------------
    struct Node
    {
      int value;
      Node *next;
      Node *previous;
    };
    
    typedef Node *NodePtr;
    
    class DList
    {
      public:
        DList();
        ~DList();
        void pushHead(int val);
        void pushTail(int val);
        void popHead();
        void popTail();
        int at(int point);
        int atTail();
        int size();
        void Print();
        void toList(char array[]);
      private:
        NodePtr Head;
        NodePtr Tail;
    };
    
    //------------------------------------------------------------------------------
    //Big Int class definitions
    //------------------------------------------------------------------------------
    class BigInt : public DList
    {
      public:
        BigInt();
        ~BigInt();
        //BigInt toBigInt(DList list);
        void toBinary(DList list);
        //void toDecimal();
    
      private:
        DList binarylist();
        DList intlist();
    };
    
    //------------------------------------------------------------------------------
    //Main
    //------------------------------------------------------------------------------
    int main()
    {
      char stuff[] = "3944A(83ED";
    
      DList list;
      list.toList(stuff);
      list.Print();
    
      system("PAUSE");
      return 0;
    }
    
    //------------------------------------------------------------------------------
    //Big Int class
    //------------------------------------------------------------------------------
    
    BigInt::BigInt()
    {
    }
    BigInt::~BigInt()
    {
    }
    void BigInt::toBinary(DList list)
    {
      int temp;
      int size = list.size();
      for(int i=0, compare;i<size;i++)
      {
        compare = 8;
        temp = list.at(i);
        for(int x=0;x<4;x++)
        {
          if(temp >= compare)
          {
            temp -= compare;
            binarylist.pushTail(1);
          }
          else
            binarylist.pushTail(0);
          compare /= 2;
        }
      }
    }
    //------------------------------------------------------------------------------
    //Double Linked List class
    //------------------------------------------------------------------------------
    DList::DList()
    {
      Head = NULL;
      Tail = NULL;
    }
    DList::~DList()
    {
    }
    void DList::pushHead(int val)
    {
      NodePtr temp;
      temp = new Node;
    
      temp->value = val;
      if(Head == NULL)
      {
     	Head = temp;
     	Head->next = NULL;
     	Head->previous = NULL;
     	Tail = Head;
       	return;
      }
      temp->next = Head;
      temp->previous = NULL;
      Head->previous = temp;
      Head = temp;
    }
    void DList::pushTail(int val)
    {
      NodePtr temp;
      temp = new Node;
    
      temp->value = val;
      if(Head == NULL)
      {
        Tail = temp;
        Head = temp;
        Head->next = NULL;
        Head->previous = NULL;
        return;
      }
      temp->next = NULL;
      temp->previous = Tail;
      Tail->next = temp;
      Tail = temp;
    }
    void DList::popHead()
    {
      NodePtr temp;
      temp = Head;
      Head = temp->next;
      temp->next = NULL;
    }
    void DList::popTail()
    {
      NodePtr temp;
      temp = Tail;
      Tail = temp->previous;
      Tail->next = NULL;
    }
    int DList::at(int point)
    {
      NodePtr temp;
      temp = Head;
      for(int i=0;i<=point;i++)
        temp = temp->next;
      return temp->value;
    }
    int DList::atTail()
    {
      return Tail->value;
    }
    int DList::size()
    {
      NodePtr temp;
      temp = Head;
      int count;
      for(count=0;temp->next != NULL;count++)
        temp = temp->next;
      return ++count;
    }
    void DList::Print()
    {
      if(Head == NULL)
        return;
      NodePtr temp;
      temp = Head;
      while(temp->next != NULL)
      {
        cout<<temp->value<<" ";
        temp = temp->next;
      }
      cout<<temp->value<<endl;
    }
    void DList::toList(char array[])
    {
      int temp;
      for(int i=strlen(array)-1;i>=0;i--)
      {
        temp = array[i];
        if(temp < 65)
          temp -= 48;
        else
          temp -= 55;
        pushHead(temp);
      }
    }
    I decided to post most of it since it really isn't that big. It's all one file so it should be easy to compile.

  11. #11
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    We posted at the same time - just wanted to make sure you noticed my post above - you have extra parentheses on your declaration of binarylist and intlist.

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    You're having problems with the function parentheses again. In BigInt, I get the feeling that both binarylist and intlist should be objects of DList rather than functions that return a DList.
    My best code is written with the delete key.

  13. #13
    Sum Dum Guy
    Join Date
    Jun 2004
    Posts
    7
    you guys are quite correct, jebus this is killing me. I feel like a total idiot, thanks a lot you guys.

    update: I just compiled with no errors, thanks again guys, damnit I should have seen this myself.
    Last edited by phats; 06-06-2004 at 07:37 PM. Reason: update

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accurately detecting function calls
    By Mole42 in forum C Programming
    Replies: 5
    Last Post: 05-17-2009, 05:01 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM

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