0
IDirect3DSurface9 *var = NULL;

IDirect3DSurface9 *** ret;

I want to assign the value dereferenced by var into the variable pointed by ret.

I did the foll:

(*(*(ret[0]))) = var;

I feel this is correct C++ syntax. But why is that I am getting compilation error as follows:

error C2679: binary '=' : no operator found which takes right hand operand of type "IDirect3DSurface9 *" (or these is no acceptable conversion).

What is the correct syntax?

10
  • 1
    Can you edit your question to remove all the bold face all caps shouting. You don't need to shout. We can here you fine. Commented Mar 22, 2012 at 10:41
  • I edited a bit, but I'm not actually sure about the intended number of asterisks now :-S Commented Mar 22, 2012 at 10:43
  • 2
    @engineerMaster: Whenever you want to say "it's a bug with [someone who is not myself]", you're probably wrong. Do try to find fault with yourself first and foremost; it's a simple numbers game to work out that that's a more productive approach. Commented Mar 22, 2012 at 10:44
  • 2
    Why do you have so many pointers? This looks horrible. Commented Mar 22, 2012 at 10:48
  • 2
    In case you haven't noticed, your Shift key is broken. Commented Mar 22, 2012 at 10:50

3 Answers 3

4

You have de-referenced the pointer 3 times. Once when you treated it as an array and used the index [0], and then twice more with the * operator. In order to be compatible with var you should de-reference only twice.

To be more explicit, let's break this down:

  • ret has type IDirect3DSurface9***.
  • ret[0] has type IDirect3DSurface9**.
  • *(ret[0]) has type IDirect3DSurface9*.
  • *(*(ret[0])) has type IDirect3DSurface9.

And clearly it follows that *(*(ret[0])) is not assignment compatible with var which has type IDirect3DSurface9*.

As to what your code really should be, I could not say for sure, but you will need to remove one level of indirection.

Sign up to request clarification or add additional context in comments.

5 Comments

Incredible!!!! Thank u so much for such a speedy answer!! I resolved it. :) I did *(*(ret[0])) = *var; Now both types LHS & RHS are same. So no compilation error.
That removes the compilation error but I'm not convinced it is correct. Surely your assignment should be at the IDirect3DSurface9* level rather than the IDirect3DSurface9 level.
Yes I can change it like (ret[0]) = var; But I have the doubt that how does it matter wheather we do the assignment at IDirectX3DSurface9 level or at IDirectX3DSurface9 level. Bcoz finally we are copying the values stored in the variable of tyoe IDirectX3DSurface9 right ? Sorry if I am wrong. Kindly correct me & clarify. Thanks.
I strongly suspect that your right hand side be var rather than *var but I can't see the rest of your code.
@engineerMaster: Don't do that - IDirect3DSurface9 is a COM interface and has no data members. Your assignment is going to compile but it will also destroy any data that the interface depends on. Only work with pointers to COM interfaces.
2

Every * and [] takes away one level of indirection. So in your code

(*(*(ret[0]))) = var; 

the left-hand-side has type IDirect3DSurface9, while the right-hand-side has type IDirect3DSurface9 *. The two types are different, that is why you get the compiler error. You need to fix this by either removing (at least one) * from the LHS or add an & (address-of operator) to the RHS (to have &var).

Comments

0

You probably want:

(*(*(ret[0]))) = &var;

or

*(*(*(ret[0]))) = var;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.