--- title: "Attribute Parameter Types (C++ Component Extensions) | Microsoft Docs" ms.custom: "" ms.date: "11/04/2016" ms.reviewer: "" ms.suite: "" ms.technology: - "cpp-windows" ms.tgt_pltfrm: "" ms.topic: "language-reference" dev_langs: - "C++" helpviewer_keywords: - "custom attributes, parameter types" ms.assetid: d9f127a3-7f08-456f-acc6-256805632712 caps.latest.revision: 5 author: "mikeblome" ms.author: "mblome" manager: "ghogen" translation.priority.ht: - "cs-cz" - "de-de" - "es-es" - "fr-fr" - "it-it" - "ja-jp" - "ko-kr" - "pl-pl" - "pt-br" - "ru-ru" - "tr-tr" - "zh-cn" - "zh-tw" --- # Attribute Parameter Types (C++ Component Extensions) Values passed to attributes must be known to the compiler at compile time. Attribute parameters can be of the following types: - `bool` - `char`, `unsigned char` - `short`, `unsigned short` - `int`, `unsigned int` - `long`, `unsigned long` - `__int64`, `unsigned __int64` - `float`, `double` - `wchar_t` - `char*` or `wchar_t*` or `System::String*` - `System::Type ^` - `System::Object ^` - `enum` ## Example ### Code ``` // attribute_parameter_types.cpp // compile with: /clr /c using namespace System; ref struct AStruct {}; [AttributeUsage(AttributeTargets::ReturnValue)] ref struct Attr : public Attribute { Attr(AStruct ^ i){} Attr(bool i){} Attr(){} }; ref struct MyStruct { static AStruct ^ x = gcnew AStruct; [returnvalue:Attr(x)] int Test() { return 0; } // C3104 [returnvalue:Attr] int Test2() { return 0; } // OK [returnvalue:Attr(true)] int Test3() { return 0; } // OK }; ``` ## Example ### Description When specifying attributes, all unnamed (positional) arguments must precede any named arguments. ### Code ``` // extending_metadata_c.cpp // compile with: /clr /c using namespace System; [AttributeUsage(AttributeTargets::Class)] ref class MyAttr : public Attribute { public: MyAttr() {} MyAttr(int i) {} property int Priority; property int Version; }; [MyAttr] ref class ClassA {}; // No arguments [MyAttr(Priority = 1)] ref class ClassB {}; // Named argument [MyAttr(123)] ref class ClassC {}; // Positional argument [MyAttr(123, Version = 1)] ref class ClassD {}; // Positional and named ``` ## Example ### Description Attribute parameters can be one-dimensional arrays of the previous types. ### Code ``` // extending_metadata_d.cpp // compile with: /clr /c using namespace System; [AttributeUsage(AttributeTargets::Class)] public ref struct ABC : public Attribute { ABC(array^){} array ^ param; }; [ABC( gcnew array {1,2,3}, param = gcnew array{2.71, 3.14})] ref struct AStruct{}; ``` ## See Also [User-Defined Attributes](../windows/user-defined-attributes-cpp-component-extensions.md)