0

So I was following a tutorial on classes and function when I met this line of code that makes me question my understanding about this subject. Here is something that look like the code:

FBullCowGame BCGame;
std::string X
FBullsAndCows Count = BCGame.Counting(X);

Now based on my understanding, BCGame is an Object created with the scope of all of the FBullCowGame now what I can't understand is how Counting(X) can send the x value from this cpp file to the function located inside the FBullCowGame. Here's the question:

1) Can the function()be used for more than just initializing the function? Like for this instance it seems sending the value of x to make it the function value.

2) Is my understanding of objects flawed or wrong?

3) If the function() can be used for sending and receiving value, does it work like it's initialized the function and gets the value of the function? Or is this understanding wrong?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • You had better grab [a good text book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and understand the basics of classes and functions from the ground up. – R Sahu Feb 21 '18 at 06:03

1 Answers1

0

In this answer I assume that the code is working

> 1) Is the function() can be used more than just initializing the
> function? like for this instance it seems sending the value of x to
> make it the function value

its not initializing the function (theres no even concept of that in C++) the function was declared and defined with a string parameter on it. when you pass a string on that function(your X) its up to the function if it wants to do something on it (maybe process or something?)

2) Is my understanding of objects is flawed or wrong?

I think you have follow the first commenter

3) If the function() can be used for sending and receiving value does it works like its initialized the function and gets the value of the function? Or is this understanding wrong?

you are not understanding what initialize is.the function is just receiving what you passed to it(your X) and then process it however it wants then returns the value of type FBullsAndCows and then assign it to Count

Anyway the best suggestion is to get a good book.
see here: The Definitive C++ Book Guide and List

Lorence Hernandez
  • 1,189
  • 12
  • 23
  • Ok so that means the parameter of that function is now the variable X is that it? Or is it just passing like the meaning giving the value of the variable? – Haha Wwkw Feb 21 '18 at 23:00
  • @HahaWwkw the latter one. its just passing the value of X. unless the parameter is taking a reference of type of string. read about pass-by-reference. – Lorence Hernandez Feb 22 '18 at 01:28
  • @HahaWwkw well if that answers your questions or clarifies you. you can mark this as answered. thanks. and welcome to stackoverflow – Lorence Hernandez Feb 23 '18 at 02:18