|
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, 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
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.
|
|
|
|
|
Tydia-kun wrote: CBuffer< T1> Buffer
Tydia-kun wrote: CBuffer< T2> RetBuf
Tydia-kun wrote: Buffer = RetBuf;
Buffer and RetBuf are different types
|
|
|
|
|
Yes, they are and that's the whole point of the overloaded assignment operator (=). It takes a CBuffer of different type (or the same type) and copies the data from that buffer into its own buffer.
But somehow the compiler didn't understand that.
|
|
|
|
|
Don't you need to implement template specialisatioin for that ?
|
|
|
|
|
Templates are templates - they can be of any type. That's why the overloaded assignment operator takes a new template type of T2. That's the power of templates.
|
|
|
|
|
what if you have
CBuffer<string> bufferOfString;
CBuffer<int> bufferofInt;
bufferOfString = bufferOfInt;
don't you need specialisation to know how to convert a CBuffer<int> to a CBuffer<string> ? It's not just a memcpy or member-member copy.
I'm just curious, I'm not very familiar with template constructs.
|
|
|
|
|
That wouldn't work unless you overlord a operator = (CBuffer<int>) or simply make a template operator = such as template<typename T2> operator = (CBuffer<T2>).
That way, the compiler can call the overloaded operator = and pass bufferOfInt to it with T2 = int.
Memcpy is a very stupid (and dangerous) way of assigning a class to another class since classes are built around handling its own memory and variables.
If you read about templates, then you know that you can specify a type for a template and the compiler will generate a function with that type when the template function is invoked. Take for example
template<typename T2> operator = (CBuffer<T2>)
When you do bufferOfString = bufferOfInt, it generates an overloaded function
operator = (CBuffer<int>)
And calls it. That's it.
|
|
|
|
|
Tydia-kun wrote: Yes, they are and that's the whole point of the overloaded assignment operator (=).
No its not. The point of the assignment operator is to assign the value of one object to the value of another. For that to be possible the objects have to be of the same type. Templates are nothing but code generation. When you declare vector<int> and vector<string> they are completely differnt types and have no common interface. If you want to perforam assignment between the two you have to write a specific operator. You cannt write a generic one
|
|
|
|
|
It's the whole point of MY overload operator =, I meant.
|
|
|
|
|
You do have some other problems you need to address. The argument to your overloaded method should be constant and it should return a reference to the left hand side of the argument so you can do things like: “a1 = a2 = a3”.
Keep your eyes open for implicit conversions, which is what you’re originally problem sounded like.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Constant? As in non-template function? If that's the case, that's a no-go.
I also added a return type of CBuffer<t>& to return *this, so it should work with a=b=c now, I think.
|
|
|
|
|
I have a SDI application.
I also have a class derived from CDialog which has no no border but some control on it. I want to use this borderless dialog as a toolbar.
Is it possible to dock this dialogbox into the SDI main frame. Frame window has EnableDocking, DockControlBar function which takes CControlBar* as an argument, but my one is derived from CDialog with attached with a dialog resource.
Also CDialog class does not have a EnableDocking method.
So, I was wondering is there any way to dock a dialog with a frame window.
Any idea will be appreciated.
Thank you
msc
|
|
|
|
|
Hi.
There was a codeline like this :
string * name = " my name is... ";
and i'm thinking why using a pointer to string typr when we can just define a string object
string name;
name = " my name is ... ";
until know i used string and pointer to string type knowing that one can't replace the otherone but in this case i'm confused. ( i'll gonna check this again in the case there was a misunderstanding ).
Thanks
int life()
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
pourang wrote: string * name = " my name is... ";
This shouldn't compile at all. What compiler are you using?
pourang wrote: string name;
name = " my name is ... ";
Or even better:
string name = " my name is ... ";
|
|
|
|
|
Hi.
I use visual studio 2005 and it works with both :
string name;
name = " ....";
and :
string name = "....";
problem is i can't find the sample code to describe better what is i can't understand. i remember that in sample code there was a line :
string * name or char * name . and there was realy no need to have a pointer and i'm thinking now : When i realy need to use a string* or char* instead strin and chr.
If you can give explain it for me so when i find the code i'll understand.
Thanks
int life()
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
pourang wrote: problem is i can't find the sample code to describe better what is i can't understand. i remember that in sample code there was a line :
string * name or char * name . and there was realy no need to have a pointer
Probably something like:
string* name = new string("something");
In general, it is better not to use this version, because you need to delete the object manually. Sometimes this may be necessary if you need the object to outlive the current scope.
|
|
|
|
|
thanks
int life()
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
hi,
Is there a function which gets mail MX records Upon giving it the domain name(as 1 of its inputs)
i don't want to use DnsQuery() function cause it doesn't work on NT4 platform.
(it only works on Windows XP or Windows 2000 Professional).
And i need it to be multiplatform...
in case there is not any function,and i need to code one on my own,can you please put me on the right track..
Example of what i need:
C:\mxlookup.exe gmail.com
gmail.com MX preference = 5, mail exchanger = gmail-smtp-in.l.google.com
gmail.com MX preference = 10, mail exchanger = alt1.gmail-smtp-in.l.google.com
gmail.com MX preference = 10, mail exchanger = alt2.gmail-smtp-in.l.google.com
gmail.com MX preference = 50, mail exchanger = gsmtp163.google.com
gmail.com MX preference = 50, mail exchanger = gsmtp183.google.com
Thanks for your time
|
|
|
|
|
The regular name lookup functions gethostbyname and getaddrinfo only return A records. Prior to Windows 2000, Windows didn't have a function to arbitrarily query DNS, you had to implement this yourself.
If you just need a command-line tool, you can use nslookup . Use set type=MX to get MX records. You can also specify -querytype=MX on the command line:
nslookup -querytype=MX gmail.com
Server: mnetics-dc2.main.mnetics.co.uk
Address: 192.168.2.250
Non-authoritative answer:
gmail.com MX preference = 10, mail exchanger = alt1.gmail-smtp-in.l.google
.com
gmail.com MX preference = 10, mail exchanger = alt2.gmail-smtp-in.l.google
.com
gmail.com MX preference = 50, mail exchanger = gsmtp163.google.com
gmail.com MX preference = 50, mail exchanger = gsmtp183.google.com
gmail.com MX preference = 5, mail exchanger = gmail-smtp-in.l.google.com
alt1.gmail-smtp-in.l.google.com internet address = 209.85.147.114
alt1.gmail-smtp-in.l.google.com internet address = 209.85.147.27
alt2.gmail-smtp-in.l.google.com internet address = 66.249.83.27
alt2.gmail-smtp-in.l.google.com internet address = 66.249.83.114
gsmtp163.google.com internet address = 64.233.163.27
gsmtp183.google.com internet address = 64.233.183.27
gmail-smtp-in.l.google.com internet address = 64.233.183.114
gmail-smtp-in.l.google.com internet address = 64.233.183.27 If you want to implement it manually, see the DNS specification (RFC 1035[^]).
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
Remove to maximize button in a SDI application. Sample code pls.
-- modified at 12:41 Thursday 18th October, 2007
|
|
|
|
|
Hakan Bulut wrote: Remove to maximize button in CView class. Sample code pls
where d'you think you are ?!
|
|
|
|
|
I'd like to where in paradise. This is a simple question.. for you i think. Sorry i get busy to you with this simple question... All of you are wasting the knowledge i think. I am always searching and following to the new tecnology on the internet area but i can not find a worthwhile doscovery. This is right, isn't this?
|
|
|
|
|
Hakan Bulut wrote: This is a simple question.. for you i think
maybe.
but what have you tried so far ?
|
|
|
|
|
maybe I am agressive
|
|
|
|
|
Hakan Bulut wrote: maybe I am agressive
or too lazy ?!
|
|
|
|