Cpp.Variable Class
Namespace: Cpp
Superclasses: ObjectWithPosition
Description
Variable class represents variables in your code. This class inherits
from the class ObjectWithPosition. You can use the predicates associated with this class and
the base class with objects of this object.
Predicates
You can report a defect on Raisable types. If a type is
Printable, it can be reported in the message. For
Variable objects, print the string obtained by the predicate
Cpp.Variable.name.
| Type | Raisable | Printable |
|---|---|---|
Lang.Int
| No | Yes |
Lang.String
| No | Yes |
Variable
| Yes | No |
This class defines these predicates that act on the Variable
objects. In addition, objects of Variable class can access the
predicates defined by the base class ObjectWithPosition. An object of Variable class is an
object of ObjectWithPosition class.
| Predicates | Description |
|---|---|
is(Variable &variable)
| Retrieves all Variable objects in your code. |
name(Variable self, Lang.String &name)
| Retrieves the name of the variable self and stores it in name. |
isUnnamed(Variable self)
| Retrieves Variable objects that are unnamed. |
qualifiedName(Variable self, Lang.String &name)
| Retrieves the fully qualified name of the variable self and stores it in name. |
type(Variable self, Cpp.Type.Type &type)
| Retrieves the type of the variable self and stores it in type. |
namespace(Variable self, Cpp.Namespace.Namespace &namespace)
| Retrieves the namespace in which the variable self is declared and stores it in namespace. |
isGloballyVisible(Variable self)
| Retrieves variables that have global visibility (not static or local). |
isFileStatic(Variable self)
| Retrieves variables that are file-static (declared with static at file scope). |
isFunctionNonStaticLocal(Variable self)
| Retrieves variables that are local to a function and not declared static. |
isFunctionParameter(Variable self)
| Retrieves variables that are function parameters. |
isFunctionStaticLocal(Variable self)
| Retrieves variables that are static locals in a function. |
isClassStatic(Variable self)
| Retrieves variables that are static members of a class. |
isDefined(Variable self)
| Retrieves variables that are defined (not just declared). |
isDeclaredAuto(Variable self)
| Retrieves variables that are declared with the auto keyword. |
isConstexpr(Variable self)
| Retrieves variables that are declared as constexpr. |
isInitializedAtDeclaration(Variable self) | Retrieves variables that are initialized at declaration. |
Examples
In a new folder
Field, initialize a new coding standard. At the command line, enter:polyspace-query-language init
In the file
main.pql, enter this content:package main // Main PQL file defines the catalog of your PQL project. // The catalog is a collection of sections. catalog FieldExample = { #[Description("Example Section")] section ExampleSection = { #[Description("Unused public field in header"),Id(myRule)] rule ExampleRule = { defect Exampledefect = when Cpp.Field.is(&field) and field.isUnused() and field.isPublic() and field.extension(&ext) and ext == ".h" and field.filename(&fnstr) raise "Unused public field in header: \"{fnstr}\"" on field } } }Create the coding standard
Field.pschk using this command at the command line:polyspace-query-language package
Using the generated coding standard, run a Bug Finder analysis on your source file. Foe example, at the command line, enter:
The analysis reports defects on the unused member variablepolyspace-bug-finder -sources src.cpp -lang cpp -checkers-activation-file Field.pschk
unusedFieldin the header filesrc.h.
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)