⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atl under the hood - part 3.mht

📁 大家知道wtl是window UI库
💻 MHT
📖 第 1 页 / 共 5 页
字号:
		cout << "Base::fun" << endl;
	}

	<SPAN class=3Dcpp-keyword>void</SPAN> doSomething() {
		T* pT =3D <SPAN class=3Dcpp-keyword>static_cast</SPAN>&lt;T*&gt;(<SPAN =
class=3Dcpp-keyword>this</SPAN>);
		pT-&gt;fun();
	}
};

<SPAN class=3Dcpp-keyword>class</SPAN> Drive : <SPAN =
class=3Dcpp-keyword>public</SPAN> Base&lt;Drive&gt; {
<SPAN class=3Dcpp-keyword>public</SPAN>:
	<SPAN class=3Dcpp-keyword>void</SPAN> fun() {
		cout &lt;&lt; "Drive::fun" &lt;&lt; endl;
	}
};

<SPAN class=3Dcpp-keyword>int</SPAN> main() {
	Base* pBase =3D NULL;
	pBase =3D <SPAN class=3Dcpp-keyword>new</SPAN> Drive;

	<SPAN class=3Dcpp-keyword>return</SPAN> <SPAN =
class=3Dcpp-literal>0</SPAN>;
}
</PRE>
      <P>This program gives an error, because we couldn't pass the =
template=20
      parameter of the base class. Now change program little bit and =
pass the=20
      template parameter. </P>
      <H3>Program 53</H3><PRE><SPAN class=3Dcpp-preprocessor>#include =
&lt;iostream&gt;</SPAN>
using <SPAN class=3Dcpp-keyword>namespace</SPAN> std;

<SPAN class=3Dcpp-keyword>template</SPAN> &lt;<SPAN =
class=3Dcpp-keyword>typename</SPAN> T&gt;
<SPAN class=3Dcpp-keyword>class</SPAN> Base {
<SPAN class=3Dcpp-keyword>public</SPAN>:
	<SPAN class=3Dcpp-keyword>void</SPAN> fun() {
		cout &lt;&lt; "Base::fun" &lt;&lt; endl;
	}

	<SPAN class=3Dcpp-keyword>void</SPAN> doSomething() {
		T* pT =3D <SPAN class=3Dcpp-keyword>static_cast</SPAN>&lt;T*&gt;(<SPAN =
class=3Dcpp-keyword>this</SPAN>);
		pT-&gt;fun();
	}
};

<SPAN class=3Dcpp-keyword>class</SPAN> Drive : <SPAN =
class=3Dcpp-keyword>public</SPAN> Base&lt;Drive&gt; {
<SPAN class=3Dcpp-keyword>public</SPAN>:
	<SPAN class=3Dcpp-keyword>void</SPAN> fun() {
		cout &lt;&lt; "Drive::fun" &lt;&lt; endl;
	}
};

<SPAN class=3Dcpp-keyword>int</SPAN> main() {
	Base&lt;Drive&gt;* pBase =3D NULL;
	pBase =3D <SPAN class=3Dcpp-keyword>new</SPAN> Drive;
	pBase-&gt;doSomething();

	<SPAN class=3Dcpp-keyword>return</SPAN> <SPAN =
class=3Dcpp-literal>0</SPAN>;
}
</PRE>
      <P>Now this program works fine and gives the same output as we =
expected=20
      i.e. </P><PRE lang=3Dtext>Drive::fun
</PRE>
      <P>But there is a problem when you inherit more then one class =
from=20
      <CODE>Base</CODE> class. To better understand it, take a look at =
the=20
      following program.</P>
      <H3>Program 54</H3><PRE><SPAN class=3Dcpp-preprocessor>#include =
&lt;iostream&gt;</SPAN>
using <SPAN class=3Dcpp-keyword>namespace</SPAN> std;

<SPAN class=3Dcpp-keyword>template</SPAN> &lt;<SPAN =
class=3Dcpp-keyword>typename</SPAN> T&gt;
<SPAN class=3Dcpp-keyword>class</SPAN> Base {
<SPAN class=3Dcpp-keyword>public</SPAN>:
	<SPAN class=3Dcpp-keyword>void</SPAN> fun() {
		cout &lt;&lt; "Base::fun" &lt;&lt; endl;
	}

	<SPAN class=3Dcpp-keyword>void</SPAN> doSomething() {
		T* pT =3D <SPAN class=3Dcpp-keyword>static_cast</SPAN>&lt;T*&gt;(<SPAN =
class=3Dcpp-keyword>this</SPAN>);
		pT-&gt;fun();
	}
};

<SPAN class=3Dcpp-keyword>class</SPAN> Drive1 : <SPAN =
class=3Dcpp-keyword>public</SPAN> Base&lt;Drive1&gt; {
<SPAN class=3Dcpp-keyword>public</SPAN>:
	<SPAN class=3Dcpp-keyword>void</SPAN> fun() {
		cout &lt;&lt; "Drive1::fun" &lt;&lt; endl;
	}
};

<SPAN class=3Dcpp-keyword>class</SPAN> Drive2 : <SPAN =
class=3Dcpp-keyword>public</SPAN> Base&lt;Drive2&gt; {
<SPAN class=3Dcpp-keyword>public</SPAN>:
	<SPAN class=3Dcpp-keyword>void</SPAN> fun() {
		cout &lt;&lt; "Drive2::fun" &lt;&lt; endl;
	}
};

<SPAN class=3Dcpp-keyword>int</SPAN> main() {
	Base&lt;Drive1&gt;* pBase =3D NULL;
	pBase =3D <SPAN class=3Dcpp-keyword>new</SPAN> Drive1;
	pBase-&gt;doSomething();
	<SPAN class=3Dcpp-keyword>delete</SPAN> pBase;

	pBase =3D <SPAN class=3Dcpp-keyword>new</SPAN> Drive2;
	pBase-&gt;doSomething();

	<SPAN class=3Dcpp-keyword>return</SPAN> <SPAN =
class=3Dcpp-literal>0</SPAN>;
}
</PRE>
      <P>This program gives error at </P><PRE>pBase =3D <SPAN =
class=3Dcpp-keyword>new</SPAN> Drive2;</PRE>
      <P>Because <CODE>pBase</CODE> is a pointer to =
<CODE>Base&lt;Drive1&gt;=20
      </CODE>not <CODE>Base&lt;Drive2&gt;</CODE>. In short you can't =
make=20
      pointer of <CODE>Base</CODE> class and store address of different =
Drive=20
      class in it. In other words you cant make an array of Base pointer =
and=20
      store address of different drive class in it, which you can do in =
case of=20
      virtual function.</P>
      <P>Hope to explore some other mysterious of ATL in next =
article.</P><!-- Article Ends --></DIV>
      <H2>About Zeeshan Amjad</H2>
      <TABLE width=3D"100%" border=3D0>
        <TBODY>
        <TR vAlign=3Dtop>
          <TD class=3DsmallText noWrap><BR></TD>
          <TD class=3DsmallText width=3D"100%">Software Engineer at =
SoftPak=20
            Financial Systems<BR><A=20
            =
href=3D"http://www.softpak.com/">http://www.softpak.com/</A><BR><BR>And=20
            sometimes teaching Object Oriented programming and C++ in =
University=20
            of Karachi as a Visiting Faculty Member.<BR><A=20
            href=3D"http://www.csku.edu.pk/">http://www.csku.edu.pk/</A>
            <P class=3DsmallText>Click <A=20
            =
href=3D"http://www.codeproject.com/script/profile/whos_who.asp?vt=3Darts&=
amp;id=3D5890">here</A>=20
            to view Zeeshan Amjad's online =
profile.</P></TD></TR></TBODY></TABLE><BR>
      <H2>Other popular ATL articles:</H2>
      <UL>
        <LI><A=20
        =
href=3D"http://www.codeproject.com/atl/shellfoldertree.asp">ShellFolderTr=
ee</A><BR><SPAN=20
        class=3Dsmalltext>Mimicking and extending the shell=92s =
folder-tree control=20
        functionality</SPAN>
        <LI><A href=3D"http://www.codeproject.com/atl/atlserver.asp">ATL =
Server -=20
        Web Application/Web Service</A><BR><SPAN class=3Dsmalltext>Web=20
        Application/Web Service development using ATL Server =
classes</SPAN>
        <LI><A =
href=3D"http://www.codeproject.com/atl/newinatl7.asp">What's new in=20
        ATL7</A><BR><SPAN class=3Dsmalltext>Overview of new classes in =
ATL7</SPAN>
        <LI><A=20
        =
href=3D"http://www.codeproject.com/atl/ietoolbartutorial.asp">Internet=20
        Explorer Toolbar (Deskband) Tutorial</A><BR><SPAN =
class=3Dsmalltext>A=20
        tutorial on Using RBDeskband and CWindowImpl ATL Object Wizards =
to=20
        create an Internet Explorer(IE) Toolbar.</SPAN></LI></UL>
      <FORM action=3D/script/rating/code/app/insert_vote.asp =
method=3Dpost><INPUT=20
      type=3Dhidden value=3D/atl/ATL_UnderTheHood_3.asp-3/27/2002 =
name=3Dvote_name>=20
      <INPUT type=3Dhidden value=3D/atl/atl_underthehood_3.asp =
name=3Dgoal>=20
      <TABLE cellSpacing=3D0 cellPadding=3D1 width=3D"100%" =
bgColor=3D#ff9900=20
        border=3D0><TBODY>
        <TR>
          <TD width=3D"100%">
            <TABLE cellSpacing=3D0 cellPadding=3D4 width=3D"100%" =
bgColor=3D#fbedbb=20
            border=3D0>
              <TBODY>
              <TR>
                <TD class=3Dsmalltext vAlign=3Dcenter>[<A=20
                  =
href=3D"http://www.codeproject.com/atl/atl_underthehood_3.asp#__top">Top<=
/A>]</TD>
                <TD vAlign=3Dcenter noWrap align=3Dright><I><B>Rate this =
Article=20
                  for us!</B></I>&nbsp;&nbsp;&nbsp;&nbsp; =
<I>Poor</I><INPUT=20
                  type=3Dradio value=3D1 name=3Drate><INPUT type=3Dradio =
value=3D2=20
                  name=3Drate><INPUT type=3Dradio value=3D3 =
name=3Drate><INPUT=20
                  type=3Dradio value=3D4 name=3Drate><INPUT type=3Dradio =
value=3D5=20
                  name=3Drate><I>Excellent</I>&nbsp;&nbsp;<INPUT =
class=3DFormButton type=3Dsubmit value=3DVote>=20
                =
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM>
      <TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%" border=3D0>
        <TBODY>
        <TR vAlign=3Dtop>
          <TD vAlign=3Dtop>
            <CENTER><A=20
            =
href=3D"http://www.codeproject.com/script/admentor/admentorredir.asp?id=3D=
544&amp;way=3Dban"=20
            target=3D_blank><IMG height=3D60 alt=3D""=20
            =
src=3D"http://www.codeproject.com/script/admentor/images/SQUARE%20LOGO4.g=
if"=20
            width=3D120 border=3D0></A><BR><FONT size=3D1><A=20
            href=3D"http://www.codeproject.com/info/MediaKit/">Premium=20
            Sponsor</A></FONT></CENTER><BR></TD>
          <TD vAlign=3Dtop noWrap align=3Dmiddle><SPAN id=3DAdBanner5><A =

            =
href=3D"http://www.codeproject.com/script/admentor/admentorredir.asp?id=3D=
411&amp;way=3Dban"=20
            target=3D_blank><IMG height=3D60=20
            alt=3D"The power of a complete PDF toolkit combined in one =
handy component"=20
            =
src=3D"http://www.codeproject.com/script/admentor/images/banner-468x60-pd=
fkit.gif"=20
            width=3D486=20
border=3D0></A></SPAN></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE=
><A=20
name=3D__comments></A>
<SCRIPT language=3DJavaScript>
function MsgVoteForm(UserID, MsgID)
{
	document.write("Rate this message: ");
	for (var i=3D1; i<=3D5;i++)
		document.write("<a href=3D'#xx" + MsgID.toString() + "xx' =
title=3D'give this message a vote of " + i.toString() + "' =
onclick=3D'RateMsg(" + UserID.toString() + ", " + MsgID.toString() + ", =
" + i.toString() + ")'><b>" + i.toString() + "</b></a> ");
	document.write(" (out of 5)");
}

function RateMsg(userid, msgid, score)=20
{=20
	=
open("/script/comments/vote.asp?js=3D1&user=3D"+userid.toString()+"&msg=3D=
"+msgid.toString()+"&score=3D"+score.toString() =
,"helpful","toolbar=3Dno,resizable=3Dyes,scrollbars=3Dyes,directories=3Dn=
o,menubar=3Dno,width=3D300,height=3D200");
	return false;
}
</SCRIPT>

<SCRIPT language=3DJavaScript>
var Selected =3D "";
var AdTime =3D new Date();

document.writeln("<iframe name=3DAdFrame width=3D0 height=3D0 =
frameborder=3D0></IFRAME>");


function SwitchMessage(elm)
{

	var now =3D new Date();
	if (Number(now.getTime() - AdTime.getTime()) > Number(5000))
	{
		AdTime =3D now;
		var loc =3D window.frames["AdFrame"];
		if (loc) loc =3D loc.document;
		if (loc) loc =3D loc.location;
		if (loc) loc.replace('/script/comments/fetchAd.asp?cat=3D2');
	}
=09
	var elmref;
	if (Selected !=3D "")
	{
		elmref =3D eval("document.getElementById('" + Selected + "_h1')");
		if (elmref) elmref.style.display =3D 'none';
		elmref =3D eval("document.getElementById('" + Selected + "_h0')");
		if (elmref) elmref.bgColor =3D '#FEF9E7';
	}
	if (Selected !=3D elm.name)=20
	{
		Selected =3D elm.name;
		elmref =3D eval("document.getElementById('" + Selected + "_h1')");
		if (elmref)=20
		{
			if (elmref.style.display=3D=3D'none') elmref.style.display=3D'';
			else elmref.style.display =3D 'none';
		}
		elmref =3D eval("document.getElementById('" + Selected + "_h0')");
		if (elmref)=20
			elmref.bgColor =3D '#99CCFF';
	}
	else
		Selected=3D"";
	=09
	window.location =3D "#xx" + Selected + "xx";

	return false;
}

</SCRIPT>

<SCRIPT language=3Djavascript event=3Donclick for=3DDynMessLink>
return SwitchMessage(this);
</SCRIPT>

<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%" bgColor=3D#ff9900 =
border=3D0>
  <TBODY>
  <TR>
    <TD width=3D"100%">
      <TABLE id=3DForumTable cellSpacing=3D1 cellPadding=3D0 =
width=3D"100%"=20
      bgColor=3D#ff9900 border=3D0>
        <FORM=20
        =
action=3D/script/comments/app/do_filtermessages.asp?main=3D/atl/atl_under=
thehood_3.asp&amp;df=3D100&amp;forumid=3D3529=20
        method=3Dpost>
        <TBODY>
        <TR>
          <TD>
            <TABLE cellSpacing=3D0 cellPadding=3D3 width=3D"100%" =
bgColor=3Dwhite=20
            border=3D0>
              <TBODY>
              <TR bgColor=3D#fbedbb>
                <TD class=3Dsmalltext noWrap><A=20
                  =
href=3D"http://www.codeproject.com/script/comments/faq.asp"><IMG=20
                  height=3D16=20
                  =
src=3D"http://www.codeproject.com/script/image

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -