wow have you tried to compile your example? Or you just took from some
dodgy web site?
Here is corrected class:
template < typename T >
class MemoryMap{
public:
MemoryMap(const T dp):data_(dp){}
friend std::ostream& operator<< (std::ostream& out,MemoryMap<T>& x)
{
size_t length=sizeof(x.data_);
unsigned char* p=reinterpret_cast< unsigned char* >(&x.data_);
Hi
I don't understand what you mean. You want a special function as a
friend to MemoryMap class?
As you wrote above code (of course it has a few syntax errors!), after
each template instantiation, you have an appropriately typed output
function. For example
for MemoryMap<char> you have an operator<< for MemoryMap<char>, for
MemoryMap<string> you
have an operator<< for MemoryMap<string> and ...
If you want an specializaed friend function, I believe you can add the
following function to
your class:
friend std::ostream& operator<< (std::ostream& out,
MemoryMap<char*>& x)
{
/* ... */
}
Regards,
-- Saeed Amrollahi
Ok! Yes, this is I mean.
Do I wirte?
//MemoryMap.hpp
template< typename T>
class MemoryMap{
public:
MemoryMap(const T):data_(T){}
friend std::ostream& operator<< (std::ostream& out, MemoryMap<T>& x);
private:
T data_;
};
//MemoryMap.cpp
std::ostream& operator<< (std::ostream& out, MemoryMap<char*>& x){
//snip
}
std::ostream& operator<< (std::ostream& out,MemoryMap<std::string>& x){
//snip
}
AFAIK, You can, please try it. BTW, you can define template function
specialization,
but by each friend declaration, each instantiated function is a friend
to instantiated
MemoryMap class template.
Regards,
-- Saeed Amrollahi