Bonjour,

J'ai un problème pour utiliser la surcharge d'opérateur<< sur basic_ostream, il ne reconnait pas le second paramètre. (const header_t& h)

voici le code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
 
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
 
template <class TChar>
struct header_trait
{
	using Type = TChar;
	using String = std::basic_string<TChar>;
	using StringStream = std::basic_stringstream<TChar>;
	using oStream = std::basic_ostream<TChar>;
};
 
template <class headerTraits>
class basic_header_t
{
	public:
	using TString = typename headerTraits::String;
	using TStream = typename headerTraits::oStream;
 
	private:
	TString message_;
 
	public:
	void set_string(const TString& s) { message_ = s; }
	TStream& operator<<(TStream& os, const header_t& h)
	{
		os << "Message: " << h.message_.c_str() << std::endl;
		return os;
	}
};
 
#if UNICODE
using header_t = basic_header_t<header_trait<wchar_t>>;
#else
using header_t = basic_header_t<header_trait<char>>;
#endif
Pour une utilisation du type:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
 
#include "header.hpp"
 
int main(int argc, char* argv[])
{
	header_t t;
	t.set_string("Hello World!");
	std::cout << t;
 
	return 0;
}
Merci d'avance pour vos réponses.