开发者

Converting to const in C++

开发者 https://www.devze.com 2023-03-05 11:03 出处:网络
C++, OS X, Carbon API. I need to pass in a const FSSpec to a method FSpOpenDF I have as follows: const FSSpec fsSpec = fFileSpec.GetFSSpec();/* is declared as FSSpec GetFSSpec() const; */

C++, OS X, Carbon API.

I need to pass in a const FSSpec to a method FSpOpenDF

I have as follows:

const FSSpec fsSpec = fFileSpec.GetFSSpec();/* is declared as FSSpec GetFSSpec() const; */

err = ::FSpOpenDF(fsSpec, 1, &refNumber);

But I get an error that is:

error: cannot convert 'const FSSpec' to 'const FSSpec*' for argument '1' to 'OSErr FSpOpenDF(const FSSpec*, SInt8, short int*)'

I have tried defining as:

const FSSpec*  fsSpec = fFileSpec.GetFSSpec();  
开发者_StackOverflow

and that doesn't help. So Obviously I am confused.

Can anyone explain the concept I am missing?


Try this:

FSSpec fsSpec = fFileSpec.GetFSSpec();
err = ::FSpOpenDF(&fsSpec, 1, &refNumber);

You seem to understand the need to take the address of an object when calling a function wanting a pointer, as you do it with refNumber; the same merely needs to be done with the fsSpec object since a const FSSpec* is expected.


Probably the FSpOpenDF function want an FSSpec pointer. Try:

err = ::FSpOpenDF(&fsSpec, 1, &refNumber);

0

精彩评论

暂无评论...
验证码 换一张
取 消