Add static vs non-static | non-stateful vs stateful
This commit is contained in:
BIN
CM2005 Object Oriented Programming/Topic 3/3.5.1/a.exe
Normal file
BIN
CM2005 Object Oriented Programming/Topic 3/3.5.1/a.exe
Normal file
Binary file not shown.
12
CM2005 Object Oriented Programming/Topic 3/3.5.1/static.cpp
Normal file
12
CM2005 Object Oriented Programming/Topic 3/3.5.1/static.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string s = "Matthew";
|
||||
std::cout << "Length of the string is " << s.length() << std::endl; // .length is stateful
|
||||
// the life of a stateful function ends with the object that it belongs to
|
||||
|
||||
// static or non-stateful function, they use memory and then return it
|
||||
std::cout << std::stod("100") << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user