Can we make a return type of our own choice in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can we make a return type of our own choice in c++

17th May 2017, 7:31 PM
shawn frost
shawn frost - avatar
5 Answers
+ 3
what do you mean with return type? you can use any return type for a function, but then you also have to return it. Or do you mean making an own data type and using it as return type?
17th May 2017, 8:00 PM
‎ɐısıօլɐ
‎ɐısıօլɐ - avatar
+ 3
how Travis already stated above you need to make a class or a struct, it can have instance variables, methods and so on, just look it up, after you've done that you can use the name of your class as data type
17th May 2017, 8:06 PM
‎ɐısıօլɐ
‎ɐısıօլɐ - avatar
+ 2
Yes, you can. You'll have to define a struct or a class and that can be the return type. class Foo { // define class or struct }; Foo someMethod () { Foo foo; //do something return foo; }
17th May 2017, 8:02 PM
Travis Avey
Travis Avey - avatar
0
making own datatype
17th May 2017, 8:02 PM
shawn frost
shawn frost - avatar
0
how to create datatype
17th May 2017, 8:04 PM
shawn frost
shawn frost - avatar