C/C++ What Types Can Be Arguments in C++ Class Methods?

  • Thread starter Thread starter spaghetti3451
  • Start date Start date
  • Tags Tags
    C++ Classes
AI Thread Summary
The discussion centers on the flexibility of method arguments in programming, specifically within a three-vector class context. It emphasizes that methods can accept arguments of any class type that is accessible to the program, not just predefined types like int or double. The confusion arises regarding the logical connection between the general statement about method arguments and the specific example of the three-vector class. The clarification provided indicates that, beyond built-in types and those defined within the same class, methods can also accept objects from other accessible classes, expanding the range of potential argument types significantly. This highlights the versatility of method parameters in object-oriented programming.
spaghetti3451
Messages
1,311
Reaction score
31
I have seen the following in a abook:

"The argument(s) of a method can be any type of object (as long as its class has been made available to the program), as well as the predefined default types of variable. For example, methods in our three-vector class are not limited to just accepting arguments of type threevector, int, double, etc."

I understand that the first statement is telling us that objects of all classes made available to the program can be used as arguments of a method.

What I do not understand, however, is how the second statement follows logically from the first. "Methods in our three-vector class are not limited to just accepting arguments of type threevector, int, double, etc." Sure! No problem! But what other types of objects are you thinking of?
 
Technology news on Phys.org
failexam said:
I have seen the following in a abook:

"The argument(s) of a method can be any type of object (as long as its class has been made available to the program), as well as the predefined default types of variable. For example, methods in our three-vector class are not limited to just accepting arguments of type threevector, int, double, etc."

I understand that the first statement is telling us that objects of all classes made available to the program can be used as arguments of a method.

What I do not understand, however, is how the second statement follows logically from the first. "Methods in our three-vector class are not limited to just accepting arguments of type threevector, int, double, etc." Sure! No problem! But what other types of objects are you thinking of?
The second sentence is saying that in addition to the built-in types (int, char, long, float, double, etc.) and types declared in the same class, objects of other classes can be used as parameters, as long as these other classes can be accessed by the class in which the method is defined.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
23
Views
2K
Replies
4
Views
2K
Replies
5
Views
3K
Replies
25
Views
2K
Replies
34
Views
4K
Replies
22
Views
3K
Replies
9
Views
2K
Replies
17
Views
2K
Back
Top