cetron
cetron

Reputation: 176

what is the meaning of percent symbol(%) and sharp symbol(#) in c++ template

here is the code from MS VC stl:

 template<typename _Fun_t,
    typename _Arg_t> inline
    binder1st<_Fun_t> bind1st(_Fun_t% _Func, _Arg_t _Left)
    {   // return a binder1st functor adapter
    typename _Fun_t::first_argument_type _Val = _Left;

    return (binder1st<_Fun_t>(_Func, _Val));
    }

and QT:

 #define Q_ARG(type, data) QArgument<type >(#type, data)

Upvotes: 0

Views: 2192

Answers (1)

Tom
Tom

Reputation: 8012

Neither of these is specific to templates.

The '%' is a Microsoft extension to C++, part of C++/CLI. It defines a tracking reference. A normal lvalue reference variable of type T& is a reference to another variable; so is T% except it refers to a managed object which might be moved by the garbage collector; the GC knows that when it moves objects it has to patch up all the tracking references to that object.

'#' is the stringify operator of the C preprocessor. It means the value of the following macro argument, surrounded by double quote marks. So this:

Q_ARG(MyType, 12345)

will expand to this:

QArgument<MyType >("MyType", 12345);

Upvotes: 6

Related Questions