锘??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美日韩国内自拍,久久精品亚洲精品,国产精自产拍久久久久久http://www.shnenglu.com/shangtang004/zh-cnSat, 29 Nov 2025 11:55:01 GMTSat, 29 Nov 2025 11:55:01 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 />浠庝笂闈㈡垜鍙互瀛﹀埌涓鐐癸細<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>
            国产视频久久久久| 亚洲高清av在线| 亚洲一区视频在线| 亚洲伦理精品| 欧美日韩在线视频一区二区| 亚洲视频在线观看一区| 亚洲无玛一区| 国产午夜亚洲精品理论片色戒| 久久九九全国免费精品观看| 久久久久久9| 亚洲欧洲日本国产| 亚洲社区在线观看| 国产一区二区三区成人欧美日韩在线观看| 久久久国产一区二区三区| 久久久久久黄| 日韩一区二区精品视频| 亚洲一区二区三区高清不卡| 国产一区二区三区免费在线观看| 欧美激情精品久久久久久蜜臀 | 香蕉亚洲视频| 久久精品成人一区二区三区| 亚洲欧洲在线免费| 一区二区久久| 亚洲成人在线网| 一本一本久久a久久精品牛牛影视| 国产精品一二三四| 欧美成人综合| 国产精品视频一| 亚洲第一精品影视| 国产精品久久久久国产精品日日| 久久久国产91| 欧美色123| 欧美18av| 国产日韩视频| 99精品视频免费观看视频| 国模精品娜娜一二三区| 一本大道久久a久久综合婷婷| 激情伊人五月天久久综合| 亚洲乱码久久| 最新中文字幕亚洲| 欧美在线观看视频一区二区三区| 一区二区高清在线观看| 久久综合电影一区| 欧美中文字幕久久| 欧美三级资源在线| 亚洲国产精品综合| 韩国一区二区三区美女美女秀| 在线视频精品一| 一本久久综合亚洲鲁鲁五月天| 久久婷婷国产综合尤物精品| 久久电影一区| 国产精品一区=区| 99精品欧美一区| 99综合视频| 欧美精彩视频一区二区三区| 欧美国产精品| 亚洲第一黄色| 久久中文久久字幕| 免费一区二区三区| 精品1区2区| 久久久久免费视频| 久久久精品一区| 国产最新精品精品你懂的| 亚洲综合精品| 久久精品成人一区二区三区蜜臀| 国产精品美女久久久久av超清 | 午夜视频久久久久久| 欧美日韩国产综合新一区| 亚洲国产导航| 日韩视频一区二区三区在线播放| 欧美freesex8一10精品| 亚洲国产精品成人va在线观看| 91久久国产综合久久| 欧美va亚洲va国产综合| 欧美激情亚洲另类| 亚洲美女少妇无套啪啪呻吟| 欧美激情精品久久久久久黑人| 欧美激情一二区| aa级大片欧美三级| 欧美日韩免费观看一区=区三区| 亚洲美女精品一区| 午夜精品久久久久久久99热浪潮| 国产精品日韩在线观看| 欧美在线影院在线视频| 免费观看成人www动漫视频| 亚洲成人直播| 欧美日韩一区二区视频在线观看| 一区二区三区精品视频| 久久精品亚洲一区二区三区浴池| 黄色亚洲在线| 欧美国产丝袜视频| 亚洲少妇一区| 久久久久久久综合| 亚洲日韩欧美视频一区| 欧美日韩一区免费| 欧美一区二区三区免费看| 欧美福利一区二区三区| 中文国产一区| 国内精品久久久| 欧美国产视频一区二区| 亚洲永久在线| 亚洲国产欧美一区二区三区同亚洲| 在线午夜精品自拍| 狠狠色噜噜狠狠色综合久 | 亚洲综合国产激情另类一区| 美女精品在线观看| 亚洲视频欧洲视频| 红桃视频国产一区| 欧美午夜在线视频| 久久久亚洲影院你懂的| 这里只有视频精品| 亚洲国产欧美日韩精品| 欧美在线一级va免费观看| 亚洲国产美女久久久久| 国产欧美日韩精品在线| 欧美国产日本在线| 欧美一级视频精品观看| 亚洲精品久久| 欧美福利视频| 久久久精品午夜少妇| 亚洲一区二区精品视频| 亚洲国产乱码最新视频| 国产亚洲一区二区在线观看| 欧美视频免费在线观看| 欧美不卡一区| 久久久久成人精品| 小辣椒精品导航| 一区二区三区不卡视频在线观看| 欧美福利视频一区| 久久综合婷婷| 久久视频一区二区| 欧美一区久久| 午夜精品福利一区二区蜜股av| 99综合视频| 日韩亚洲成人av在线| 亚洲黄色影片| 亚洲高清电影| 亚洲二区视频在线| 伊人久久大香线蕉综合热线| 国产综合欧美| 一区久久精品| 尤物yw午夜国产精品视频| 国产一区二区成人| 狠狠综合久久av一区二区老牛| 国产欧美日韩在线播放| 国产欧美日韩综合| 国产日韩专区在线| 韩国女主播一区| 在线观看不卡av| **性色生活片久久毛片| 亚洲黄色成人| 亚洲精品国产精品久久清纯直播| 亚洲国产精品精华液网站| 亚洲国产精品视频一区| 亚洲精品系列| 亚洲一区二区免费看| 亚洲欧美精品在线观看| 欧美在线黄色| 久久最新视频| 亚洲电影第1页| 日韩视频免费| 午夜激情一区| 久久资源av| 欧美日韩免费视频| 国产精品视频99| 伊人蜜桃色噜噜激情综合| 91久久夜色精品国产九色| 一个人看的www久久| 亚洲欧美日韩爽爽影院| 久久露脸国产精品| 欧美激情片在线观看| 日韩一级精品| 久久国产一区| 欧美伦理a级免费电影| 国产欧美日韩| 亚洲欧洲综合| 久久riav二区三区| 国产日韩av高清| 一区在线视频| 欧美一站二站| 免费在线播放第一区高清av| 亚洲精品乱码| 午夜一区二区三区不卡视频| 久久在精品线影院精品国产| 欧美日韩午夜视频在线观看| 国产免费成人| 99综合电影在线视频| 久久精品男女| 野花国产精品入口| 久久这里有精品视频| 国产精品美女在线| 最新日韩欧美| 久久人人爽爽爽人久久久| 日韩亚洲欧美成人一区| 久久久噜噜噜久久人人看| 欧美精品系列| 在线观看久久av| 久久黄色影院| 一本久道久久综合狠狠爱| 快she精品国产999|