What does “Class* &cls” mean in C++'s function definition?

前端 未结 4 2288
后悔当初
后悔当初 2020-12-15 01:45

I know Class *cls is a pointer, and Class &cls takes the address, but what is

void fucction1( Class *&cls)

If I have Class c

4条回答
  •  别那么骄傲
    2020-12-15 02:39

    Class c;
    Class* c_ptr = &c;
    function1(c_ptr);
    

    Would work. But note that rvalue-references is only possible with C++0x which most compilers haven't fully implemented them. Thus the following wouldn't work:

    Class c;
    function1(&c);
    

提交回复
热议问题