UniversityDatabse.h

#include<string>
#include<stdexcept>
#include<iostream>
#include<map>
#include "UniversityPerson.h"

class UniversityPerson ; 

using namespace std ; 

#ifndef UNIVERSITYDATABASE_H
#define UNIVERSITYDATABASE_H


class UniversityDatabase
{

public:


    UniversityDatabase() ; 
    ~UniversityDatabase() ; 
    void print() ;   
    void Create(UniversityPerson  *p ) ; 
    void Delete1( string name   ) ; 
    void Delete2( string id ) ; 
    UniversityPerson *Lookup1(string id  ) ;  
    UniversityPerson *Lookup2(string name ) ; 


private:

    map<name , (UniversityPerson *)>NAME ; 
    map<id, (UniversityPerson *)> ID ; 




} ; 

#endif

UniversityPerson.h

#include<string>
#include<stdexcept>
#include<iostream>

#ifndef UNIVERSITYPERSON_H
#define UNIVERSITYPERSON_H

using namespace std ; 


class UniversityPerson
{

 private:

  string name ; 
  string id ; 
  string emailadress ;
  string phonenumber ; 
  static bool flag ; 

 public:
  UniversityPerson(string thename , string theid , string theemailadress ,string thephonenumber) ; 
  ~ UniversityPerson() ; 
  virtual  string toString() ;
  string getname() ; 
  string getid() ; 
  string getemailadress() ; 
  string getphonenumber() ;
  void setemailadress(string email ) ; 
  void setphonenumber( string phone) ; 
  void setflag( string indicateflag ) ; 
  bool getflag() ; 


};

#endif

compile it with

g++ -c UniversityDatabase.h and get

UniversityDatabase.h:33: error: ânameâ was not declared in this scope
UniversityDatabase.h:33: error: template argument 1 is invalid
UniversityDatabase.h:33: error: template argument 2 is invalid
UniversityDatabase.h:33: error: template argument 3 is invalid
UniversityDatabase.h:33: error: template argument 4 is invalid
UniversityDatabase.h:34: error: âidâ was not declared in this scope
UniversityDatabase.h:34: error: template argument 1 is invalid
UniversityDatabase.h:34: error: template argument 2 is invalid
UniversityDatabase.h:34: error: template argument 3 is invalid
UniversityDatabase.h:34: error: template argument 4 is invalid

what do I have to fix?

UniversityDatabase.cpp

#include "UniversityDatabase.h" 
#include <string>
#include<iostream>
#include <algorithm>
#include<map>
#include "UniversityPerson.h"

using namespace std ; 



bool comp_strings(string& s1, string& s2)
{
if(s1 < s2 )
return 1 ; 

else return  0 ; 

}


void UniversityDatabase::print()
{
sort(ID.begin(), ID.end(), comp_strings);
sort(NAME.begin(), NAME.end(), comp_strings);

map<string,UniversityPerson *>::iterator it ; 

  for ( it = NAME.begin() ; it != NAME.end(); ++it ){

	(it->second)->toString()  ; 		 


	}

}

void UniversityDatabase::Create( UniversityPerson *p)
{

NAME.insert(pair<string,UniversityPerson *>(p->getname(),p)) ;
ID.insert(pair<string,UniversityPerson *>(p->getname(),p )) ; 


}





void UniversityDatabase::Delete1( string id )
{

if( ID.find(id) != ID.end()  )

	ID.erase(id) ; 





}




void UniversityDatabase::Delete2( string name )
{

if(NAME.find(name) != NAME.end() )

	NAME.erase(name) ; 





}



 UniversityPerson *UniversityDatabase::Lookup1(string id  ){

if(ID.find(id) == ID.end() ){

throw invalid_argument(" Person doesn't exists") ; 

}


return ID.find(id)->second ; 


}







    UniversityPerson *UniversityDatabase::Lookup2(string name ) 
{

if(NAME.find(name) == NAME.end()){

throw invalid_argument(" Person doesn't exists") ; 

}


return NAME.find(name)->second ; 



}

fixed it now when i compile it i get

/usr/include/c++/4.3/bits/stl_algo.h: In function âvoid std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â:
UniversityDatabase.cpp:25:   instantiated from here
/usr/include/c++/4.3/bits/stl_algo.h:4820: error: no match for âoperator-â in â__last - __firstâ
/usr/include/c++/4.3/bits/stl_algo.h: In function âvoid std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â:
/usr/include/c++/4.3/bits/stl_algo.h:4822:   instantiated from âvoid std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â
UniversityDatabase.cpp:25:   instantiated from here
/usr/include/c++/4.3/bits/stl_algo.h:1842: error: no match for âoperator-â in â__last - __firstâ
/usr/include/c++/4.3/bits/stl_algo.h:1844: error: no match for âoperator+â in â__first + 16â
/usr/include/c++/4.3/bits/stl_algo.h:1845: error: no match for âoperator+â in â__first + 16â
/usr/include/c++/4.3/bits/stl_algo.h: In function âvoid std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â:
/usr/include/c++/4.3/bits/stl_algo.h:1849:   instantiated from âvoid std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â
/usr/include/c++/4.3/bits/stl_algo.h:4822:   instantiated from âvoid std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â
UniversityDatabase.cpp:25:   instantiated from here
/usr/include/c++/4.3/bits/stl_algo.h:1775: error: no match for âoperator+â in â__first + 1â
/usr/include/c++/4.3/bits/stl_algo.h:1849:   instantiated from âvoid std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â
/usr/include/c++/4.3/bits/stl_algo.h:4822:   instantiated from âvoid std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â
UniversityDatabase.cpp:25:   instantiated from here
/usr/include/c++/4.3/bits/stl_algo.h:1779: error: invalid initialization of reference of type âstd::string&â from expression of type âstd::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*>â
/usr/include/c++/4.3/bits/stl_algo.h:1781: error: no match for âoperator+â in â__i + 1â
/usr/include/c++/4.3/bits/stl_pair.h: In member function âstd::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*>& std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*>::operator=(const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*>&)â:
/usr/include/c++/4.3/bits/stl_pair.h:73: error: non-static const member âconst std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*>::firstâ, can't use default assignment operator
/usr/include/c++/4.3/bits/stl_algo.h: In function âvoid std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â:
/usr/include/c++/4.3/bits/stl_algo.h:1782: note: synthesized method âstd::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*>& std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*>::operator=(const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*>&)â first required here
/usr/include/c++/4.3/bits/stl_algo.h: In function âvoid std::__unguarded_linear_insert(_RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Tp = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*>, _Compare = bool (*)(std::string&, std::string&)]â:
/usr/include/c++/4.3/bits/stl_algo.h:1785:   instantiated from âvoid std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â
/usr/include/c++/4.3/bits/stl_algo.h:1849:   instantiated from âvoid std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â
/usr/include/c++/4.3/bits/stl_algo.h:4822:   instantiated from âvoid std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*> >, _Compare = bool (*)(std::string&, std::string&)]â
UniversityDatabase.cpp:25:   instantiated from here
/usr/include/c++/4.3/bits/stl_algo.h:1735: error: invalid initialization of reference of type âstd::string&â from expression of type âstd::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, UniversityPerson*>â

You don't need to try and sort the NAME map by the name string, it will already be sorted in this way. So, just delete lines 24 and 25 in UniversityDatabase.cpp

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.