Click here to Skip to main content
15,909,498 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow do I check if a string is valid for saving? Pin
monsieur_jj18-Oct-07 16:19
monsieur_jj18-Oct-07 16:19 
AnswerRe: How do I check if a string is valid for saving? Pin
John R. Shaw18-Oct-07 17:04
John R. Shaw18-Oct-07 17:04 
AnswerRe: How do I check if a string is valid for saving? Pin
User 58385218-Oct-07 17:09
User 58385218-Oct-07 17:09 
QuestionHow to use VIPS API on MFC program? Pin
TooShy2Talk18-Oct-07 14:39
TooShy2Talk18-Oct-07 14:39 
QuestionBroken code? Pin
Tydia-kun18-Oct-07 11:26
Tydia-kun18-Oct-07 11:26 
AnswerRe: Broken code? Pin
Stephen Hewitt18-Oct-07 14:33
Stephen Hewitt18-Oct-07 14:33 
QuestionRe: Broken code? Pin
Maximilien18-Oct-07 14:49
Maximilien18-Oct-07 14:49 
AnswerRe: Broken code? [modified] Pin
Tydia-kun18-Oct-07 15:26
Tydia-kun18-Oct-07 15:26 
What indeed? That it doesn't call the overloaded operator function is quite enough.
Showing all the code would be pretty long and boring and irrelevant, so I'll show the important snippets of the declaration/definition of the variables and the class.

template< class T1, class T2><br />
long GetRegValuePtrNew(const char* strKey, const char* strName, CBuffer< T1> Buffer, /*bool bUseTempBuffer, */CBuffer< T2> RetBuf = (T2*)THROW_ERROR, DWORD* pType = NULL) throw(...)<br />
{<br />
	...<br />
	Buffer = RetBuf;<br />
	...<br />
}<br />
<br />
template< typename T> class CBuffer<br />
{<br />
	...<br />
	template< typename T2> void operator = (CBuffer< T2>& rBuffer);<br />
	...<br />
};<br />


There's the basic declaration, so the obvious thing is that the compiler should generate code that calls CBuffer::operator =, but it doesn't, as you can see from the asm snippet I gave you.
This is all the relevant parts of the code, but I can post the whole function/class if it's necessary. It's just that it would be so long.
I also want to made it clear that I intentionally put spaces after a < since otherwise it's interpreted as HTML code and not shown. In REAL code I would NEVER do that, since I HATE it, it looks POOR. Just wanted to say that Wink | ;)

EDIT:
Actually, I seem to have fixed the problem.
The problem was that the compiler was confused, but it still shouldn't have generated faulty code. It should complain, should it not?

Consider this:
As you saw above, the assignment operator takes a CBuffer of a DIFFERENT type than the type of the actual class (it takes T2 instead of T).
In the above template, T1 and T2 = UINT64, the same type.

Adding the following:

void operator = (CBuffer<T>& rBuffer);

...Fixes the problem. It seems the compiler gets confused and cannot interpret T2 as T (so if there's a var of CBuffer< UINT64>, the assignment operator can't take a CBuffer< UINT64> as argument, because it's the same type as the class type T).
I got around it by adding an additional operator that takes the class's type T (CBuffer< T>) as argument and now it works. Of course, this shouldn't really be, AFAIK.

Here is the new code:
		void operator = (CBuffer<T>& rBuffer)<br />
		{<br />
			Assign(rBuffer);<br />
		}<br />
<br />
		template<typename T2> void operator = (CBuffer<T2>& rBuffer)<br />
		{<br />
			Assign(rBuffer);<br />
		}<br />
<br />
		template<typename T2> void Assign(CBuffer<T2>& rBuffer)...<br />


As plainly visible, both overloads call Assign, which takes a new template type T2 as argument, and both functions (well, I only tested the first, though) call the Assign function just fine.

But even so, if there's no suitable overload, it should call the copy constructor, which again, it didn't. This seems like a compiler bug.
GeneralRe: Broken code? Pin
User 58385218-Oct-07 17:04
User 58385218-Oct-07 17:04 
GeneralRe: Broken code? Pin
Tydia-kun19-Oct-07 0:35
Tydia-kun19-Oct-07 0:35 
GeneralRe: Broken code? Pin
Maximilien19-Oct-07 1:39
Maximilien19-Oct-07 1:39 
GeneralRe: Broken code? Pin
Tydia-kun19-Oct-07 1:41
Tydia-kun19-Oct-07 1:41 
QuestionRe: Broken code? Pin
Maximilien19-Oct-07 3:26
Maximilien19-Oct-07 3:26 
AnswerRe: Broken code? Pin
Tydia-kun19-Oct-07 3:38
Tydia-kun19-Oct-07 3:38 
GeneralRe: Broken code? Pin
User 58385221-Oct-07 12:51
User 58385221-Oct-07 12:51 
GeneralRe: Broken code? Pin
Tydia-kun23-Oct-07 7:13
Tydia-kun23-Oct-07 7:13 
GeneralRe: Broken code? Pin
John R. Shaw18-Oct-07 17:45
John R. Shaw18-Oct-07 17:45 
GeneralRe: Broken code? Pin
Tydia-kun19-Oct-07 0:36
Tydia-kun19-Oct-07 0:36 
QuestionHow to dock a dialog box Pin
s196675m18-Oct-07 11:18
s196675m18-Oct-07 11:18 
Questionstring vs string* Pin
pourang18-Oct-07 8:40
pourang18-Oct-07 8:40 
AnswerRe: string vs string* Pin
Nemanja Trifunovic18-Oct-07 9:08
Nemanja Trifunovic18-Oct-07 9:08 
GeneralRe: string vs string* Pin
pourang18-Oct-07 10:49
pourang18-Oct-07 10:49 
GeneralRe: string vs string* Pin
Nemanja Trifunovic18-Oct-07 12:03
Nemanja Trifunovic18-Oct-07 12:03 
GeneralRe: string vs string* Pin
pourang19-Oct-07 1:23
pourang19-Oct-07 1:23 
QuestionGetting MX records without using DnsQuery() Pin
jadothebest18-Oct-07 6:55
jadothebest18-Oct-07 6:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.