Sender: hhuu (I love XXX), the letter area: programming Title: Boost :: Ref News Station: BBS Shuimu Tsinghua Station (Sat May 25 02:03:27 2002)
1 Introduction
(It was really wrong. Originally, just think about why REF needs, the result example is too simple, Laws gives an opinion, check it, do not meet. Re-explain, please re-examine.)
The purpose of REF is to put the selected right to the user when a template function is available. (If you are a temporary variable, you should not use ref; otherwise, you should use REF.)
A simple idea is the method of using a function overload. However, this method cannot be implemented. If the template function can be offset, it is also a good method, but unfortunately this method doesn't even go into the ANSI standard.
2, use
Ref is used in such an occasion, a ref (), explicitly tells the compiler on the parameter. Here, if you want, it is the value transfer.
SAMPLE:
#include
Template
INT main () {qq huxw; sample:
#include
Template
INT main () {qq huxw; foo (REF (HUXW)); cout << huxw.k << Endl; huxw.k = 11; foo (huxw); cout << huxw.k << Endl; return 0; }
3, realize
Such a class, the efficiency is very important, otherwise it is to paint the tiger. ;) Quote Pass, think about it and pointer is nothing wrong. ;)
Yes, it is achieved with a pointer.
Template
Fourth, other
This thing Boost :: REF, simple and clever, really interesting.
-
※ Modified: · hhuu at May 25 21:44:44 Modified this article · [From: 166.111.172.6] ※ Source: · BBS Shuimu Tsinghua Station Smth.edu.cn · [from: 166.111.172.6]