Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

EXPLAIN STATE METHOD IN C++ OOP ?


  • Please log in to reply

#1
pllaybuoy

pllaybuoy

    New Member

  • Member
  • Pip
  • 2 posts
Hello guys I am learning c++ now , and I am confused with state methods in c++'s oop
, to me they look no different than overloaded constructors , can anybody please explain them to me in simple words ?
  • 0

Advertisements


#2
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,357 posts
Hey there pllaybuoy and welcome to GeeksToGo,

I hope I can provide you with an appropriate answer relating to your question...

If i am correct you want to better understand what a state method/function is in simple words?

This is better known as a "functor", which is basically a class/struct that can be called as a function; But this function is special being that it can hold state. So you are kind of correct in saying it "looks no different than a constructor", that's because you call it using its constructor, but what makes it different is when you call it a second time using its constructor it keeps the original state of the original object. Instead of looking at it as a constructor, think of it more as a parameter of a local function that changes a variable within your local class. But when the first object is created with its specific state, that state is kept the same until the object is destroyed.

In other words if you create the object which stores a variable int static_x = 10, then you call that object like it was a function and have it add what ever is in the parameter to the firstly set variable functor(int x), so functor(5) would output a value of 15.

So I really hope that simple description helps out, simply put a state method is a method that keeps state. hehe Posted Image

Please let me know if I can better explain myself in some area of the text, or if you require any other help.

Peace Out Posted Image

  • 0

#3
pllaybuoy

pllaybuoy

    New Member

  • Topic Starter
  • Member
  • Pip
  • 2 posts
Hey hi thank you , and I did a little research myself and found that it is actually programming paradigm , maybe you are talking about that STATE MACHINE thing , no ?
and oops , sorry I meant state MEMBER not method , it could be any variable that defines the state of a class or anything its just a programming paradigm not part of any language
  • 0






Similar Topics

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP