锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久av红桃一区二区小说,欧美一级专区免费大片,亚洲欧洲日韩在线http://www.shnenglu.com/shangtang004/zh-cnSat, 29 Nov 2025 12:52:48 GMTSat, 29 Nov 2025 12:52:48 GMT60Handle assignment to self in operator=http://www.shnenglu.com/shangtang004/archive/2013/05/17/200357.html欖忓皻鍫?/dc:creator>欖忓皻鍫?/author>Fri, 17 May 2013 07:00:00 GMThttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200357.htmlhttp://www.shnenglu.com/shangtang004/comments/200357.htmlhttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200357.html#Feedback0http://www.shnenglu.com/shangtang004/comments/commentRss/200357.htmlhttp://www.shnenglu.com/shangtang004/services/trackbacks/200357.html
  • Make sure operator= is well-behaved when an object is assigned to itself. Techniques include comparing addresses of source and target objects, careful statement ordering, and copy-and-swap.

  • Make sure that any function operating on more than one object behaves correctly if two or more of the objects are the same.



]]>
Have assignment operators return a reference to *thishttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200356.html欖忓皻鍫?/dc:creator>欖忓皻鍫?/author>Fri, 17 May 2013 04:06:00 GMThttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200356.htmlhttp://www.shnenglu.com/shangtang004/comments/200356.htmlhttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200356.html#Feedback0http://www.shnenglu.com/shangtang004/comments/commentRss/200356.htmlhttp://www.shnenglu.com/shangtang004/services/trackbacks/200356.htmlThis is only a convention; code that doesn't follow it will compile. However, the convention is followed by all the built-in types as well as by all the types in  the standard library (e.g., string, vector, complex, tr1::shared_ptr, etc.). Unless you have a good reason for doing things differently, don't.



]]>
Never call virtual functions during construction or destructionhttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200355.html欖忓皻鍫?/dc:creator>欖忓皻鍫?/author>Fri, 17 May 2013 03:27:00 GMThttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200355.htmlhttp://www.shnenglu.com/shangtang004/comments/200355.htmlhttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200355.html#Feedback0http://www.shnenglu.com/shangtang004/comments/commentRss/200355.htmlhttp://www.shnenglu.com/shangtang004/services/trackbacks/200355.html
base class constructors execute before derived class constructors, derived class data members have not been initialized when base class constructors run. If virtual functions called during base class construction went down to derived classes, the derived class functions would almost certainly refer to local data members, but those data members would not yet have been initialized.Calling down to parts of an object that have not yet been initialized is inherently dangerous, so C++ gives you no way to do it.

#include <iostream>
#include <string>
#include <cstdlib>
void print(std::string str){std::cout << str<< std::endl;}
class Transaction {
    public:
        Transaction()
        {
            print("Transaction Constructor");
            logTransaction();
        }
        virtual void logTransaction() const // =0;
        {
            print("Transaction Log");
        }
};
class BuyTransaction: public Transaction
{
    public:
        BuyTransaction(){   print("BuyTransaction Constructor");}
        virtual void logTransaction() const
        {
            print("BuyTransaction Log");
        }
};
int main()
{
    BuyTransaction dbc;
    //dbc.logTransaction();
}
pure virtual functions cannot link.
[shangtang@BTSOM-1 study]$ g++ TestT.cpp
TestT.cpp: In constructor 'Transaction::Transaction()':
TestT.cpp:14: warning: abstract virtual 'virtual void Transaction::logTransaction() const' called from constructor
/tmp/ccXFzaHv.o: In function `Transaction::Transaction()':
TestT.cpp:(.text._ZN11TransactionC2Ev[Transaction::Transaction()]+0x7f): undefined reference to `Transaction::logTransaction() const'
collect2: ld returned 1 exit status
virtual function can compile, run, but with surprise result
[shangtang@BTSOM-1 study]$ ./a.out
Transaction Constructor
Transaction Log
BuyTransaction Constructor

The only way to avoid this problem is to make sure that none of your constructors or destructors call virtual functions on the object being created or destroyed and that all the functions they call obey the same constraint.


]]>
Prevent exceptions from leaving destructorshttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200354.html欖忓皻鍫?/dc:creator>欖忓皻鍫?/author>Fri, 17 May 2013 02:56:00 GMThttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200354.htmlhttp://www.shnenglu.com/shangtang004/comments/200354.htmlhttp://www.shnenglu.com/shangtang004/archive/2013/05/17/200354.html#Feedback0http://www.shnenglu.com/shangtang004/comments/commentRss/200354.htmlhttp://www.shnenglu.com/shangtang004/services/trackbacks/200354.html
Depending on the precise conditions under which such pairs of simultaneously active exceptions arise, program execution either terminates or yields undefined behavior. In this example, it yields undefined behavior.
C++ does not like destructors that emit exceptions!
#include <iostream>
#include <vector>
struct Exception
{
    Exception(){std::cout << "Exception Constructor" << std::endl;}
    ~Exception(){std::cout << "Exception Destructor" << std::endl;}
};
class Widget {
public:
  ~Widget() {std::cout << "Widget Destructor" << std::endl; throw Exception();
  }        //this might emit an exception
  void print(){std::cout << "print" << std::endl;}
};
                
void doSomething();
int main()
{
    doSomething();
}
void doSomething()
{
  std::vector<Widget> v;
  v.push_back(Widget());
  v.push_back(Widget());
  v.push_back(Widget());
  v.push_back(Widget());
  std::vector<Widget>::iterator it = v.begin();
  while(it != v.end())
  {
    std::cout << "end" << std::endl;
    (*it).print();
    it++;
  }
}
complie with g++
[shangtang@BTSOM-1 study]$ ./a.out
Widget Destructor
Exception Constructor
terminate called after throwing an instance of 'Exception'
Aborted (core dumped)
There are two primary ways to avoid the trouble.

   1, Terminate the program if catch a exception, typically by calling std::abort (cstdlib)
  2, 
Swallow the exception if catch a exception, print a log


]]>
Virtual destructor from effective c++ edition 3http://www.shnenglu.com/shangtang004/archive/2013/05/13/200220.html欖忓皻鍫?/dc:creator>欖忓皻鍫?/author>Mon, 13 May 2013 06:45:00 GMThttp://www.shnenglu.com/shangtang004/archive/2013/05/13/200220.htmlhttp://www.shnenglu.com/shangtang004/comments/200220.htmlhttp://www.shnenglu.com/shangtang004/archive/2013/05/13/200220.html#Feedback0http://www.shnenglu.com/shangtang004/comments/commentRss/200220.htmlhttp://www.shnenglu.com/shangtang004/services/trackbacks/200220.htmlwhy ? because C++ specifies that when a derived class object is deleted through a pointer to a base class with a non-virtual destructor, results are undefined.What typically happens at runtime is that the derived part of the object is never destroyed

2, if a class is not intended to be a base class, making the destructor virtual is usually a bad idea. 
why?  if a class have virtual functions, it has extra overhead(vptr).

3, In fact, many people summarize the situation this way: declare a virtual destructor in a class if and only if that class contains at least one virtual function

4,Sometimes, however, you have a class that you'd like to be abstract, but you don't have any pure virtual functions.
solution: declare pure virtual destructor.
There is one twist, however you must provide a definition for the pure virtual destructor, or linker will complain.

5, Not all base classes are designed to be used polymorphically. Neither the standard string type, for example, nor the STL container typesare designed to be base classes at all, much less polymorphic ones.


 
 


]]>
sizeof 鏄湪緙栬瘧鏃舵墽琛岃繕鏄繍琛屾椂http://www.shnenglu.com/shangtang004/archive/2013/01/24/197524.html欖忓皻鍫?/dc:creator>欖忓皻鍫?/author>Thu, 24 Jan 2013 02:26:00 GMThttp://www.shnenglu.com/shangtang004/archive/2013/01/24/197524.htmlhttp://www.shnenglu.com/shangtang004/comments/197524.htmlhttp://www.shnenglu.com/shangtang004/archive/2013/01/24/197524.html#Feedback0http://www.shnenglu.com/shangtang004/comments/commentRss/197524.htmlhttp://www.shnenglu.com/shangtang004/services/trackbacks/197524.html
// A simple, compile-time assertion facility
#define STATIC_ASSERT(x) \
   do { typedef int a[(x) ? 1 : -1]; } while(0)

int main()
{
   STATIC_ASSERT(sizeof(int) <= sizeof(long));  // Passes
   STATIC_ASSERT(sizeof(double) <= sizeof(int)); // Fails 
   return 0;
}

]]>
綾繪ā鏉夸腑鐨勫弸鍏冨嚱鏁?/title><link>http://www.shnenglu.com/shangtang004/archive/2013/01/21/197434.html</link><dc:creator>欖忓皻鍫?/dc:creator><author>欖忓皻鍫?/author><pubDate>Mon, 21 Jan 2013 02:48:00 GMT</pubDate><guid>http://www.shnenglu.com/shangtang004/archive/2013/01/21/197434.html</guid><wfw:comment>http://www.shnenglu.com/shangtang004/comments/197434.html</wfw:comment><comments>http://www.shnenglu.com/shangtang004/archive/2013/01/21/197434.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/shangtang004/comments/commentRss/197434.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/shangtang004/services/trackbacks/197434.html</trackback:ping><description><![CDATA[template <typename T> class dataList<br />{<br />   public:<br /><div>      friend ostream& operator<<(ostream& outStream, const dataList <T> &outList);</div>}<br /><div>template <typename T> ostream& operator<<(ostream& outStream, const dataList <T> &outList)<br />{<br />   //....<br />   return outStream;<br />}<br />int main(int argc, char* argv[])<br />{<br />   dataList <int> testList;<br />   cout << testList;<br />}</div>榪欎釜紼嬪簭鍛樻槸閾炬帴涓嶈繃錛?br />閿欒淇℃伅錛?br /><div> warning: friend declaration âstd::ostream& operator<<(std::ostream&, const dataList<T>&)â declares a non-template function</div><div> note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here)</div><div>/tmp/cc9DSuka.o: In function `main':</div><div><span style="color: red;">undefined reference to</span> `operator<<(std::basic_ostream<char, std::char_traits<char> >&, dataList<int> const&)'</div><div>collect2: ld returned 1 exit status</div><div>閿欒鍘熷洜瑙i噴<br /><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">The problem is that the compiler is not trying to use the templated <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">operator<<</code> you provided, but rather a non-templated version.</p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">When you declare a friend inside a class you are injecting the declaration of that function in the enclosing scope. The following code has the effect of declaring (and not defining) a free function that takes a <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">non_template_test</code> argument by constant reference:</p><pre prettyprint="" prettyprinted"="" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; line-height: 18px;"><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">class</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> non_template_test </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">{</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">friend</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">void</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> f</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> non_template_test </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">const</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">&</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">);</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">};</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// declares here:</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// void f( non_template_test const & );</span></code></pre><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">The same happens with template classes, even if in this case it is a little less intuitive. When you declare (and not define) a friend function within the template class body, you are declaring a free function with that exact arguments. Note that you are declaring a function, not a template function:</p><pre prettyprint="" prettyprinted"="" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; line-height: 18px;"><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">template</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">typename</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">class</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> template_test </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">{</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">friend</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">void</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> f</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> template_test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">const</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">&</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> t </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">);</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">};</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// for each instantiating type T (int, double...) declares:</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// void f( template_test<int> const & );</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// void f( template_test<double> const & );</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #2b91af;">int</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> main</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">()</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">{</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> template_test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #800000;"><int></span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> t1</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">;</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> template_test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #800000;"><double></span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> t2</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">;</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">}</span></code></pre><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">Those free functions are declared but not defined. The tricky part here is that those free functions are not a template, but regular free functions being declared. When you add the template function into the mix you get:</p><pre prettyprint="" prettyprinted"="" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; line-height: 18px;"><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">template</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">typename</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">class</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> template_test </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">{</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">friend</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">void</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> f</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> template_test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">const</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">&</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">);</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">};</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// when instantiated with int, implicitly declares:</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// void f( template_test<int> const & );</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">template</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">typename</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">void</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> f</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> template_test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">const</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">&</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> x </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">)</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">{}</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// 1</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #2b91af;">int</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> main</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">()</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">{</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> template_test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #800000;"><int></span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> t1</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">;</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> f</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> t1 </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">);</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">}</span></code></pre><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">When the compiler hits the main function it instantiates the template <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">template_test</code> with type <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">int</code>and that declares the free function <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">void f( template_test<int> const & )</code> that is not templated. When it finds the call <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">f( t1 )</code> there are two <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">f</code> symbols that match: the non-template <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">f( template_test<int> const & )</code> declared (and not defined) when <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">template_test</code> was instantiated and the templated version that is both declared and defined at <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">1</code>. The non-templated version takes precedence and the compiler matches it.</p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">When the linker tries to resolve the non-templated version of <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">f</code> it cannot find the symbol and it thus fails.</p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">What can we do? There are two different solutions. In the first case we make the compiler provide non-templated functions for each instantiating type. In the second case we declare the templated version as a friend. They are subtly different, but in most cases equivalent.</p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;"><strong style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">Having the compiler generate the non-templated functions for us:</strong></p><pre prettyprint="" prettyprinted"="" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; line-height: 18px;"><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">template</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">typename</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">class</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> test </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">{</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">friend</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">void</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> f</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">const</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">&</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">)</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">{}</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">};</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// implicitly</span></code></pre><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">This has the effect of creating as many non-templated free functions as needed. When the compiler finds the friend declaration within the template <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">test</code> it not only finds the declaration but also the implementation and adds both to the enclosing scope.</p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;"><strong style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">Making the templated version a friend</strong></p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">To make the template a friend we must have it already declared and tell the compiler that the friend we want is actually a template and not a non-templated free function:</p><pre prettyprint="" prettyprinted"="" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; line-height: 18px;"><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">template</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">typename</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">class</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">;</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// forward declare the template class</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">template</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">typename</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">void</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> f</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">const</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">&</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">);</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// forward declare the template</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">template</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">typename</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">class</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> test </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">{</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">friend</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">void</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> f</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><>(</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">const</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">&</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">);</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: gray;">// declare f<T>( test<T> const &) a friend</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">};</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">template</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">typename</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">void</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> f</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> test</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">T</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">></span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b;">const</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">&</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">)</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">{}</span></code></pre><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">In this case, prior to declaring <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">f</code> as a template we must forward declare the template. To declare the <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">f</code>template we must first forward declare the <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">test</code> template. The friend declaration is modified to include the angle brackets that identify that the element we are making a friend is actually a template and not a free function.<br />寮曠敤鑷?nbsp;<span style="font-family: verdana, 'courier new'; line-height: 21px;">http://stackoverflow.com/questions/1810753/overloading-operator-for-a-templated-class<br />浠庝笂闈㈡垜鍙互瀛﹀埌涓鐐癸細(xì)<br />1錛?緙栬瘧鍣ㄥ尮閰嶆柟娉曟椂闈炴ā鏉垮嚱鏁頒紭鍏堟ā鏉垮嚱鏁?br />2, 鍙嬪厓鍑芥暟妯℃澘蹇呴』鎻愬墠澹版槑</span></p></div><img src ="http://www.shnenglu.com/shangtang004/aggbug/197434.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/shangtang004/" target="_blank">欖忓皻鍫?/a> 2013-01-21 10:48 <a href="http://www.shnenglu.com/shangtang004/archive/2013/01/21/197434.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>linux linkhttp://www.shnenglu.com/shangtang004/archive/2013/01/17/197339.html欖忓皻鍫?/dc:creator>欖忓皻鍫?/author>Thu, 17 Jan 2013 06:01:00 GMThttp://www.shnenglu.com/shangtang004/archive/2013/01/17/197339.htmlhttp://www.shnenglu.com/shangtang004/comments/197339.htmlhttp://www.shnenglu.com/shangtang004/archive/2013/01/17/197339.html#Feedback0http://www.shnenglu.com/shangtang004/comments/commentRss/197339.htmlhttp://www.shnenglu.com/shangtang004/services/trackbacks/197339.htmlLinux Shell鐨勯氶厤絎︿笌姝e垯琛ㄨ揪寮?/a> http://blog.csdn.net/chen_dx/article/details/2463495

]]>
c++ resource allocation new statementhttp://www.shnenglu.com/shangtang004/archive/2012/11/27/195721.html欖忓皻鍫?/dc:creator>欖忓皻鍫?/author>Tue, 27 Nov 2012 02:03:00 GMThttp://www.shnenglu.com/shangtang004/archive/2012/11/27/195721.htmlhttp://www.shnenglu.com/shangtang004/comments/195721.htmlhttp://www.shnenglu.com/shangtang004/archive/2012/11/27/195721.html#Feedback0http://www.shnenglu.com/shangtang004/comments/commentRss/195721.htmlhttp://www.shnenglu.com/shangtang004/services/trackbacks/195721.html

Perform every resource allocation (e.g., new) in its own code statement which immediately gives the new resource to a manager object (e.g., auto_ptr).

This guideline is easy to understand and remember, it neatly avoids all of the exception safety problems in the original problem, and by mandating the use of manager objects it helps to avoid many other exception safety problems as well. This guideline is a good candidate for inclusion in your team's coding standards

link http://www.gotw.ca/gotw/056.htm

file I/O http://www.zwqxin.com/archives/cpp/use-sstream.html



]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美日本高清一区| 一卡二卡3卡四卡高清精品视频| 亚洲第一在线综合在线| 国产精品高潮久久| 亚洲第一页中文字幕| 国产欧美一区二区视频| 亚洲精品在线免费| 亚洲国产毛片完整版| 午夜精品视频在线观看一区二区| 亚洲免费av观看| 麻豆精品一区二区av白丝在线| 亚洲欧美日韩中文播放| 欧美国产一区二区三区激情无套| 久久夜色精品国产噜噜av| 国产精品系列在线| 一区二区三区回区在观看免费视频| 1024成人网色www| 欧美亚洲一区在线| 欧美一区二区在线免费播放| 欧美特黄一区| 一区二区三区四区在线| 亚洲天堂第二页| 欧美另类videos死尸| 亚洲激情av在线| 最新国产精品拍自在线播放| 久久综合一区二区| 免费成人在线观看视频| 伊人久久久大香线蕉综合直播| 欧美在线播放| 美日韩精品视频| 亚洲观看高清完整版在线观看| 久久精品一区二区三区不卡| 久久一区二区三区超碰国产精品| 国产一区二区观看| 欧美在线www| 免费av成人在线| 91久久精品国产91久久性色tv | 亚洲一区中文| 午夜欧美大尺度福利影院在线看| 国产精品视频网| 午夜精品理论片| 久久天天躁狠狠躁夜夜av| 曰本成人黄色| 欧美激情一区二区三区不卡| 99精品免费视频| 欧美在线高清| 在线观看日韩专区| 欧美精品九九| 一区二区三区日韩在线观看| 欧美在线看片a免费观看| 国内精品亚洲| 欧美激情国产日韩| 亚洲一区二区三区777| 久久一日本道色综合久久| 亚洲国产日韩一区二区| 欧美视频在线观看 亚洲欧| 午夜精品美女自拍福到在线 | 亚洲欧美激情在线视频| 久久久精品一区| 亚洲人成在线观看网站高清| 国产精品久久久久久久午夜 | 在线观看视频一区二区| 欧美日韩国产美| 欧美主播一区二区三区| 亚洲国产福利在线| 久久国产主播| 99在线精品视频在线观看| 国产午夜精品久久久| 欧美精品18+| 欧美一区二视频在线免费观看| 欧美激情一二区| 久久青草久久| 亚洲一级二级| 亚洲黄色一区| 国产欧美视频一区二区| 欧美日韩国产a| 久久综合给合久久狠狠色| 这里只有视频精品| 91久久综合| 欧美暴力喷水在线| 欧美中日韩免费视频| 一区二区三区不卡视频在线观看 | 久久久久久久久久久久久久一区 | 久久精品91| 中国成人亚色综合网站| 亚洲黄色成人网| 国产婷婷一区二区| 欧美三日本三级三级在线播放| 狂野欧美激情性xxxx| 欧美一区二区三区在线视频| 在线亚洲成人| 日韩视频欧美视频| 亚洲黄色高清| 欧美国产免费| 巨胸喷奶水www久久久免费动漫| 亚洲欧美成人| 亚洲一区二区在| 日韩视频免费观看高清完整版| 在线视频观看日韩| 影音先锋日韩资源| 伊人狠狠色丁香综合尤物| 国产日韩欧美综合| 国产乱码精品1区2区3区| 国产精品高潮呻吟久久av黑人| 欧美屁股在线| 欧美日韩一级大片网址| 欧美精品在线观看91| 欧美国产激情二区三区| 欧美成人激情视频| 欧美aⅴ一区二区三区视频| 久久躁狠狠躁夜夜爽| 卡通动漫国产精品| 欧美第十八页| 欧美激情无毛| 欧美日韩一区二区三区在线视频 | 亚洲国产高清aⅴ视频| 亚洲成色777777女色窝| 在线观看欧美日韩国产| 亚洲欧洲精品一区二区三区波多野1战4 | 久久av免费一区| 久久精品水蜜桃av综合天堂| 久久亚洲高清| 欧美高清在线视频| 欧美新色视频| 国产日韩欧美黄色| 在线精品亚洲一区二区| 亚洲精品欧美精品| 亚洲一区二区视频在线| 欧美在线地址| 你懂的视频一区二区| 亚洲欧洲在线免费| 在线亚洲免费视频| 久久国产精品毛片| 欧美高清视频| 国产精品视频一二| 在线欧美一区| 在线亚洲美日韩| 久久国产视频网| 欧美激情精品久久久久久变态| 亚洲日本电影在线| 午夜在线精品偷拍| 免费精品99久久国产综合精品| 欧美日韩亚洲一区| 国内精品久久久| 99综合电影在线视频| 久久久久久久国产| 亚洲精品乱码| 欧美主播一区二区三区美女 久久精品人| 麻豆国产精品777777在线| 国产精品久久久999| 在线免费精品视频| 午夜精品电影| 欧美国产日产韩国视频| 亚洲一区二区不卡免费| 蜜桃精品久久久久久久免费影院| 国产精品久久久久久超碰| 在线观看亚洲精品视频| 午夜久久美女| 亚洲人成免费| 久久男女视频| 国产欧美日韩精品一区| 99re热这里只有精品免费视频| 久久久久国产成人精品亚洲午夜| 亚洲卡通欧美制服中文| 久久婷婷人人澡人人喊人人爽| 欧美性色aⅴ视频一区日韩精品| 在线观看欧美日韩| 久久久久久久久久久成人| 99精品99| 欧美精品一区二区久久婷婷| 狠狠综合久久| 欧美一区二区三区在| 日韩亚洲国产欧美| 欧美激情一区二区三区蜜桃视频| 国语精品一区| 久久成人国产| 亚洲午夜国产成人av电影男同| 欧美精品一区二区久久婷婷| 1204国产成人精品视频| 久久精品国产精品亚洲| 亚洲夜晚福利在线观看| 欧美四级剧情无删版影片| 日韩性生活视频| 亚洲黄网站黄| 女同一区二区| 最新中文字幕一区二区三区| 老司机午夜免费精品视频 | 一区二区久久| 欧美日韩国产va另类| 99re6热只有精品免费观看| 亚洲第一区中文99精品| 裸体素人女欧美日韩| 亚洲电影毛片| 欧美大片专区| 欧美不卡视频一区| 亚洲精品少妇| 亚洲精品国产品国语在线app| 欧美mv日韩mv国产网站| 亚洲精品一二三区| 亚洲乱码久久|