这个问题显然假设我们不想使用这种类型的模板(无论出于何种原因).
class Product
{
public:
Product( decltype(mPrice) price_, decltype(mLabel) label_ ) // 1.
: mPrice( price_ ), mLabel( label_ )
{}
decltype(mPrice) price() const {return mPrice;} // 2.
decltype(mLabel) label() const {return mLabel;} // 2.
private:
float mPrice ; // type might later be changed to more acurate floating point abstraction
std::string mLabel; // type might later be changed by a special localization-oriented string
};
Run Code Online (Sandbox Code Playgroud)
问题是:在C++ 0x中是1.和2.允许和可能(甚至是特定的)?