define a function returning struct pointer

前端 未结 5 1905
天命终不由人
天命终不由人 2021-02-14 06:49

Please bear with me, i m from other language and newbie to c and learning it from http://c.learncodethehardway.org/book/learn-c-the-hard-way.html

struct Person {         


        
5条回答
  •  逝去的感伤
    2021-02-14 07:01

    Structs are not pointers (or references) by default in C/C++, as they are for example in Java. Struct Person Function() would therefor return struct itself (by value, making a copy) not a pointer.

    You often don't want to create copies of objects (shallow copies by default, or copies created using copy constructors) as this can get pretty time consuming soon.

提交回复
热议问题