(queue*)this)->queue::qput does not have class type

This is a discussion on (queue*)this)->queue::qput does not have class type within the C++ Programming forums, part of the General Programming Boards category; i got this error: Code: cplusplus_dellicult.cpp:23: error: ((queue*)this)->queue::qput does not have class type cplusplus_dellicult.cpp:26: error: ((queue*)this)->queue::qput does not have class ...

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    230

    (queue*)this)->queue::qput does not have class type

    i got this error:
    Code:
    cplusplus_dellicult.cpp:23: error: ((queue*)this)->queue::qput does not have class type
    cplusplus_dellicult.cpp:26: error: ((queue*)this)->queue::qput does not have class type
    can anyone help to fix this ?
    thanks..
    Code:
    class queue{
    	private:
    		string buf[10];
    		int *ptrfront;
    		int *ptrback;
    	public:
    		void init();
    		void qput();
    		void qget();
    		void print();
    };
    
    
    void queue::init(){
    	int i;
    		for(i=0; i<10; i++){
    			qput.buf[i] = NULL;
    		}
    		for(i=0; i<10; i++){
    			qput.buf[i] = NULL;
    		}
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,660
    Why do you write qput.buf[i] instead of just buf[i]? Oh, and why do you loop twice? Furthermore, why not write a constructor instead of an init member function?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    Why do you write qput.buf[i] instead of just buf[i]? Oh, and why do you loop twice? Furthermore, why not write a constructor instead of an init member function?
    Look, i tried both! But, even with buf[i] the code crashes. My double loop is wrong...sorry! And i can not have a constructor cause i am not familiar yet and because this particular exercise says to call init() so as to initialize whatever i want. take a look at my newer version...

    Code:
    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    class queue{
    	private:
    		string buf[10];
    		int *ptrfront;
    		int *ptrback;
    	public:
    		void init();
    		string qput();
    		void qget();
    		void print();
    };
    
    /*
    void queue::init(){
    	int i;
    		for(i=0; i<10; i++){
    			buf[i] = NULL;
    		}
    }
    */
    
    string queue::qput(){
    	string temp_buf;
    		cout << "Type a string to insert";
    		cin.get(temp_buf, 81, '\n');
    return temp_buf;
    }
    
    void queue::print(){
    	int i;	
    		for(i=0; i<10; i++){
    			cout << buf[i] << endl;
    		}
    }
    
    int main(){
    	queue A;
    	queue B;
    	
    	int i;
    	
    		for(i=0; i<5; i++){
    			A.qput();
    		}
    		A.print();
    		B.print();
    return 0;
    }
    the bold parts are wrong ? how can i initialize to NULL the buf[ ]? is it necessary ?

    thanks...

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,660
    Quote Originally Posted by brack
    And i can not have a constructor cause i am not familiar yet and because this particular exercise says to call init() so as to initialize whatever i want.
    Which might be okay, except that you did not actually call init in your global main function.

    To me, your queue interface is wrong. You should have a node class and a queue class. The queue class will handle insertion and removal of nodes from the queue, by keeping a singly linked list of nodes in which the tail is tracked. The node class will have a std::string member variable, and also a next pointer. It can be private so you do not have to worry about its interface.

    The request of input from the user will then be done in the global main function, or helper functions called from the global main function. The queue class itself would not be concerned with input/output.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    You should include <string>. Also, no you cannot initialise buf[i] to NULL, as it's no pointer. You might want it initialised to an empty string but it already does that. So, no, you don't need to initialise anything there.

    But that's only a small part of the actual problems with this code...

  6. #6
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    ok...more over i got it...BUT if the way i do it was the only way? how can i fix my problems...

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,660
    Quote Originally Posted by brack
    BUT if the way i do it was the only way?
    What exactly is the way that you have in mind? If you're talking about your current queue class with its flawed interface, then you're on your own. I see no point in teaching you to shoot yourself.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    look..yes i mean about this...the problem is that the way i' ll do is not depending on me! it is a homework! which means that i can not do different things from these i told if i want to pass the C++ lesson. i do not agree with this but there is nothing i can do to change this...i would appreciate your help even with this exercise...

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,660
    What exactly were you told to do?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    write a C++ program that manages two queues A, B with have strings of max size 10, via a class queue. queue class must have a init() method, an insert method called qput(), a get method called qget() and a print method called print(). Also, when we get an element from A it must be inserted to B.

    Do this inserting 8 stings in A, geting 4, inserting other 2 and printing the results...everything is here....

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,660
    As far as I can tell, it does not forbid what I suggested, except for the init and print member functions, but those are fine. qget, besides allowing you to get the front of the queue, probably should also remove the element at the front of the queue.

    You are not forbidden to use a node helper class, and you can choose the parameters and return types of your functions. It does look like you are required to store a char[10] or char[11] in each node instead of a std::string, depending on how you interpret "strings of max size 10".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    i mean that we have 10 strings the maximun...ok! thanks...so, now can you tell me a plan? what exactly to do?

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,660
    Start by deciding on the interface of the queue class. To get a better idea of how it should work, pretend that you already implemented the queue class, and write out how you would write the main function with your queue class in order to "do this inserting 8 stings in A, geting 4, inserting other 2 and printing the results".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    basically i thought to use a while loop and inside the swich way. so,

    Code:
    while(...){
        switch(...){
              case 1:
                                read the number of string that i want to insert to A. suppose that are n.
                                for(i=0; i<n; i++){
                                               call the qput();
                                 }
                                //insert strings to A.
              break;
              case 2:
                                //get stings and insert to B
              break;
              default:
                             exit(1);
             }
              print the so far things...
    }
    how is this? :/
    Last edited by brack; 11-11-2010 at 02:46 PM. Reason: want to add something...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 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, 08:18 PM
  2. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  3. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 05:17 AM
  4. class errors
    By romeoz in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2003, 07:57 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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