Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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,354 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

#4
Saurabh12

Saurabh12

    Member

  • Member
  • PipPip
  • 20 posts

A method in object-oriented programming is a procedure associated with a class. A method defines the behavior of the objects that are created from the class. Another way to say this is that a method is an action that an object is able to perform. The association between method and class is called binding.


  • 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