Noob question about a use a friend class

This is a discussion on Noob question about a use a friend class within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; class IntNode { private: int x; IntNode* p; public: IntNode( int n = 0, ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    2

    Noob question about a use a friend class

    Code:
    #include <iostream>
    using namespace std; 
    
    class IntNode {
    private: 
    	int x;
    	IntNode* p;
    public:
    	IntNode( int n = 0, IntNode* volgende = NULL) : x (n), p(volgende)
    	{}
    	friend class Lijst;
    	
    };
    
    
    class Lijst{
    private:
    	IntNode * head;
    public: 
    	
    	Lijst() : head ( NULL ){}
    	
    	void voegToe(int x){
    		head = new IntNode(x,head);
    	}
    	
    	void print() {
    		IntNode* wijzer = head;
    		while (wijzer != NULL) {
    			cout<< wijzer -> x << endl;
    			wijzer = wijzer -> p;
    		}
    		cout << endl;
    	}
    	
    	void buildUp(int getal){
    		
    		int i=0;
    		int hulp = getal;
    		int helpInt;
    		char buffer [255];
    		snprintf (buffer, 255, "%d", hulp);
    		
    		while(buffer[i] != '\0'){
    			
    			if (buffer[i] > 47 && buffer[i] < 58){
    				helpInt = buffer[i]-48;
    				buffer[i];
    				i++;
    			}
    		head = new IntNode(helpInt,head);
    		}
    		
    	}
    	
    	Lijst reverse(){ // not processed
    		Lijst* hulpLijst;
    		return *hulpLijst;
    	}
    	
    	bool operator > (Lijst lijst2){ //also not processed
    		bool boolHulp = true;
    		return boolHulp;
    	}
    };
    
    
    int main () {
    	Lijst lijst1, lijst2;
    	
    	lijst1.print();
    	lijst1.buildUp(3456);
    	lijst1.print();
    	lijst2.Lijst.reverse();	// has to look 6543
    	lijst2.print();
    	 
     // I have to use it like this lijst2.????.reverse();
    // I know I can use this one lijst2.reverse(lijst2)
    	
    return 0;
    }

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Code:
    //have you considered this?
    lijst2.reverse();
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    2
    yes of course...
    I know that's the only way...

    lijst2.reverse...
    but It was a question in an test, maybe it was a typo !
    I thought it gives a trick to use lijst2.( lijst ).reverse(); with the parameter from the lijst1
    it's ok, thx mate

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with friend class declaration in a namespace
    By Angus in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2008, 12:29 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. Simple Short Class Question
    By Travis Dane in forum C++ Programming
    Replies: 2
    Last Post: 12-24-2002, 06:12 PM

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