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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)