[Dev-C++] Templats and I/O operators (<< >>)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Maya <Esc...@ne...> - 2003-12-28 21:09:33
|
I am having problems with the inserters and extractors in a template,
can someone help, thanks a bunch!
#ifndef JME_INDEX_H
#define JME_INDEX_H
#include <iostream>
namespace jme{
/*
See:
http://new-brunswick.net/workshop/c++/faq/containers-and-templates.html#faq-34.15
for more information regarding the next pre-declarations
*/
// pre-declare the template class itself
template<typename K, typename D> class Index;
// convince the compiler that the operator<< function is a template
template<typename K, typename D> std::ostream& jme::operator<<
(std::ostream& os, const Index<K,D>& obj);
// convince the compiler that the operator<< functions is a template
template<typename K, typename D> std::istream& jme::operator>>
(std::istream& is, Index<K,D>& obj);
template<typename K, typename D> class Index{
private:
std::string version; // class version
K Key;
D Data;
public:
Index(K const& kx, D const& dx): Key(kx), Data(dx){ }
//Copy C'tor
Index(const jme::Index<K, D>& rhs): Key(rhs->Key),
Data(this->Data){}
const K& getKey() const { return Key;}
const D& getData() const { return Data;}
template<typename K, typename D>
friend std::ostream& jme::operator<< (std::ostream& os,
const Index<K,D>& obj){
return os << obj.getKey << " " << obj.getData();
}
template<typename K, typename D>
friend std::istream& jme::operator>> (std::istream& is,
Index<K,D>& obj){
is >> obj.Key;
is >> obj.Data;
return is;
}
}; //Index
} // jme
#endif
--
FYI
http://www.astro.umd.edu/~marshall/abbrev.html
E-Mail Policy
http://www.vif.com/users/escalante/Email_Policy.html
* You cannot exercise your power to a point of humiliation.
- Jean Chretien
* The media's the most powerful entity on earth. They have the
power to make the innocent guilty and to make the guilty
innocent, and that's power.
- Malcom X
* "Innocent until proven guilty", no... not in Canada!!
|