Copy constructor is not called for copy-initialization or optimized?

后端 未结 2 1757
栀梦
栀梦 2021-01-25 05:30

If copy constructor is made private then in

Case 1: No error, the compiler doesn\'t care if the copy constructor was defined in class.

2条回答
  •  醉梦人生
    2021-01-25 06:02

    Case 1: No error, the compiler doesn't care if the copy constructor was defined in class.

    T a = ("Copy Initialization"); should give an error because there's no suitable constructor to convert from "const char [20]" to "T"

    Did you mean T a = std::string("Copy Initialization"); ?

    Does it directly optimizes the copy without being noticing that if the constructor was made private?

    No it can't. Compilers usually perform syntactic and semantic analysis prior to the code optimization phase.

提交回复
热议问题