{{fbdoc item="title" value="CONST (Member)"}}----
Specifies that a member procedure is read only.

{{fbdoc item="syntax"}}##
	[[KeyPgType|Type]] //typename//
		[[KeyPgDeclare|Declare]] **Const** [[KeyPgSub|Sub]]|[[KeyPgFunction|Function]]|[[KeyPgProperty|Property]]|[[KeyPgOperator|Operator]] ...
	End Type
	
	[**Const**] [[KeyPgSub|Sub]]|[[KeyPgFunction|Function]]|... //typename// ...
		...
	End [[KeyPgSub|Sub]]|[[KeyPgFunction|Function]]|...
##
{{fbdoc item="desc"}}
	Specifies that a method does not change the object it is called on. The hidden ##[[KeyPgThis|This]]## parameter will be considered read-only. The declaration can be read as 'invoking a const method promises not to change the object', and the compiler will error if the member procedure tries to change any of the data fields, or calls a non-const member procedure. 
	
	Read-only (##**Const**##) declarations are a measure of type safety that can be read as 'promises not to change.'  The compiler uses the const declarations to check operations on variables and parameters and generate an error at compile time if their data could potentially change.  There is no runtime overhead for using ##**Const**## qualifiers since all of the checks are made at compile time.
	
	Constructors and destructors cannot be ##**Const**## (not useful).
	Member procedures can not be both ##**Const**## and ##[[KeyPgStaticMember|Static]]## since static member procedures do not have a hidden ##[[KeyPgThis|This]]## parameter.
	
	For methods with ##**Const**## in their declaration, ##**Const**## can also be specified on the corresponding method bodies, for improved code readability.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/udt/const-proc.bas"}}%%(freebasic)
'' Const Member Procedures

type foo
  x as integer
  c as const integer = 0
  declare const sub Inspect1()
  declare const sub Inspect2()
  declare sub Mutate1()
  declare sub Mutate2()
end type

''
sub foo.Mutate1()
  '' we can change non-const data fields
  x = 1

  '' but we still can't change const data
  '' fields, they are promised not to change
  '' c = 1 '' Compile error

end sub

''
sub foo.Mutate2()
  '' we can call const members
  Inspect1()

  '' and non-const members
  Mutate1()

end sub

''
sub foo.Inspect1()
  '' can use data members
  dim y as integer
  y = c + x

  '' but not change them because Inspect1()
  '' is const and promises not to change foo
  '' x = 10 '' Compile error

end sub

''
sub foo.Inspect2()
  '' we can call const members
  Inspect1()

  '' but not non-const members
  '' Mutate1() '' Compile error

end sub
%%

{{fbdoc item="diff"}}
	- New to ""FreeBASIC""

{{fbdoc item="see"}}
	- ##[[KeyPgConst|Const]]##
	- ##[[KeyPgConstQualifier|Const (Qualifier)]]##
	- ##[[KeyPgDim|Dim]]##
	- ##[[KeyPgType|Type]]##

{{fbdoc item="back" value="CatPgProcedures|Procedures"}}{{fbdoc item="back" value="CatPgUserDefTypes|User Defined Types"}}