1

I got the following problem: I want to assign a value which is pointed at to another value. How I do this? I tried it this way:

trialstr(0,0) = *stress(0);

But this did not work. I received this error message:

‘stress’ cannot be used as a function

I hope you can help me.

4
  • 1
    Parentheses are used for functions. To access elements of an array you are looking at square brackets ([]). Also, we need more code to be able to help you. Commented Jun 16, 2015 at 11:36
  • Please show the relevant declarations. What is stress? What is trialstr? Commented Jun 16, 2015 at 11:37
  • 2
    You might also want to read about how to ask good questions, and learn how to create a Minimal, Complete, and Verifiable Example. Commented Jun 16, 2015 at 11:38
  • The declaratons are the following: LINBOX::Matrix<3,3> trialstr and LINBOX::Matrix<6,1> *stress, Pileborg thank you for the advice. Iwill keep that in mind for my next posts Commented Jun 16, 2015 at 11:42

1 Answer 1

1

It seems to be a problem with operator precedence, the function-call operation has higher precedence than the indirection (dereference) operator, which means that from the compiler point of view you are doing

*(stress(0))

in other words you try to dereference what stress(0) returns.

What you want (I assume) is to first dereference the stress pointer an then use the function call operator () on the dereferenced pointer:

(*stress)(0)
Sign up to request clarification or add additional context in comments.

1 Comment

Pileborg that was exactly what I need. Thank you!

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.