Template Inheritence

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
41
42
43
44
45
46
47
48
49
50
template < typename T > class BString {

	protected:
		std::allocator < T >	_Buf;
		Uint32			Length;
		

	public:

		BString	operator += ( LPSTR Text );
		BString operator += ( LPCSTR Text );
		BString operator += ( LPWSTR Text );
		BString operator += ( LPCWSTR Text );

		BString operator *= ( Uint32 Count );

};


class StringW : protected BString < wchar_t > {

	public:
			StringW ( LPSTR Text );
			StringW ( LPCSTR Text );
			StringW ( LPWSTR Text );
			StringW ( LPCWSTR Text );

		void	operator= ( LPSTR Text );
		void	operator= ( LPCSTR Text );
		void	operator= ( LPWSTR Text );
		void	operator= ( LPCWSTR Text );

		wchar_t*	operator[] ( unsigned int Pos );

};

class StringA : protected BString < char > {

	public:
			StringA ( LPSTR Text );
			StringA ( LPCSTR Text );
			StringA ( LPWSTR Text );
			StringA ( LPCWSTR Text );

		void	operator= ( LPSTR Text );
		void	operator= ( LPCSTR Text );
		void	operator= ( LPWSTR Text );
		void	operator= ( LPCWSTR Text );

};


In the above code, I have the base class BString and derived classes StringA and StringW. I know that I can't define template methods from outside of its file, but I'll define them later. I al.so realize that the return types for the overloaded += operator is incorrect, but that's a part of my second question

My first question is if I did the inheritance right, but I'm pretty sure I have.

Then my second question is: How should I set up the return values for the overloaded operator +=? Is it possible to keep them in the base class, or do I have to now declare them in the derived classes now?
Last edited on
It looks to me like this is what you were trying to do:
1
2
typedef Bstring<char> StringA;
typedef Bstring<wchar_t> StringW;
If it means that I can still overload the assignment operator and create a constructor for each one individually, then yes. How would I go about doing this? But then that still leaves the obvious question of: how would I go about doing it?

EDIT:

Alright, nevermind, forget this. I forgot all about the basic_string class, and I'm just going to use that and create my own typedefs for them.
Last edited on
Topic archived. No new replies allowed.