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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

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