Thread: Help figuring out error

  1. #1
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391

    Help figuring out error

    I keep getting this error when I compile:
    Code:
    In function 'std::ostream& operator<<(std::ostream&, User&)':
    error: no match for 'operator<<' in 'os << u->User::userID'
    note: candidates are: std::ostream& operator<<(std::ostream&, User&)
    And here's the operator
    Code:
    friend std::ostream& operator<<( std::ostream& os, User& u ){
    		os << u.userID << " " << u.name << " " << u.systemKey << " " << u.accessKey;
    		return os;
    	}
    I'm not even calling the "<<" operator anywhere in my code. My code only creates three users, that's it. I can't get past compile.

    Any help is most appreciated!
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  2. #2
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    ????
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    What is u.userID? An int of some kind? You'll have to give more of an example.

  4. #4
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Here's my code so far.

    users.h
    Code:
    #ifndef USERS_H_
    #define USERS_H_
    
    #include <string>
    
    typedef unsigned char uchar;
    typedef unsigned int uint;
    
    class User{
    	
    	public:
    		User( uint id, std::string name );
    		virtual ~User(){};
    		const uchar& checkSystemKey() const;
    		const uchar& checkAccessKey() const;
    		void setSystemKey( uchar& system );
    		void setAccessKey( uchar& access );
    		
    	friend std::ostream& operator<<( std::ostream& os, User& u ){
    		os << u.userID << " " << u.name << " " << u.systemKey << " " << u.accessKey;
    		return os;
    	}
    
    	protected:
    		User( const User& );
    		User& operator=( const User& );
    		uint userID;
    		std::string name;
    		uchar systemKey;
    		uchar accessKey;
    };
    
    class SysAdmin : public User{
    
    	public:
    		SysAdmin( uint id, std::string name, uchar system );
    		virtual ~SysAdmin(){};
    		void addSystemUser( User& user );
    		void setUserAccess( User& user, uchar& access );
    		
    	private:
    		uchar mySystemKey;
    };
    
    class SiteAdmin : public SysAdmin{
    
    	public:
    		SiteAdmin( uint id, std::string name, uchar system );
    		User* createBasicUser( uint id, std::string name );
    		User* createSysAdmin( uint id, std::string name, uchar system );
    };
    
    #endif
    users.cpp
    Code:
    #include "users.h"
    
    User::User( uint id, std::string name )
    : userID( id ), name( name ), systemKey( 0x00 ), accessKey( 0x00 ) {}
    
    inline const uchar& User::checkSystemKey() const{
    	return systemKey;
    }
    
    inline const uchar& User::checkAccessKey() const{
    	return accessKey;
    }
    
    inline void User::setSystemKey( uchar& system ){
    	systemKey = systemKey | system;
    }
    
    inline void User::setAccessKey( uchar& access ){
    	accessKey = accessKey | access;
    }
    
    SysAdmin::SysAdmin( uint id, std::string name, uchar system )
    : User( id, name ), mySystemKey( system ) {}
    
    inline void SysAdmin::addSystemUser( User& user ){
    	user.setSystemKey( mySystemKey );
    }
    
    inline void SysAdmin::setUserAccess( User& user, uchar& access ){
    	user.setAccessKey( access );
    }
    
    SiteAdmin::SiteAdmin( uint id, std::string name, uchar system )
    : SysAdmin( id, name, system ) {}
    
    User* SiteAdmin::createBasicUser( uint id, std::string name ){
    	return new User( id, name );
    }
    
    User* SiteAdmin::createSysAdmin( uint id, std::string name, uchar system ){
    	return new SysAdmin( id, name, system );
    }
    main.cpp
    Code:
    #include <iostream>
    #include <string>
    
    #include "users.h"
    
    int main(){
    
    	SiteAdmin Chris( 1, "Chris", 0x80 );
    	User* Eric = Chris.createBasicUser( 2, "Eric" );
    	User* Mike = Chris.createSysAdmin( 3, "Mike", 0x40 );
    	
    	return 0;
    }
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So when compiling users.cpp, where oh where is #include <iostream>?

  6. #6
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    ah, that worked.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

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. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM