Computer Science Canada Class subprograms cannot be subprogram variables |
Author: | Dusk Eagle [ Sat Apr 04, 2009 11:07 pm ] | ||
Post subject: | Class subprograms cannot be subprogram variables | ||
I am having trouble with a certain part of a program I'm writing, listed below. What I want to do is have a class with a function that accepts as a parameter an instance of itself, and can then call it's various public procedures and functions on the instance of that class. However, when I try to do this, I get an error message saying "Class subprograms cannot be subprogram variables".
Can anyone offer any help? Thanks. |
Author: | richcash [ Sun Apr 05, 2009 4:28 am ] |
Post subject: | Re: Class subprograms cannot be subprogram variables |
If you define your function isHungry with parentheses (meaning takes no parameters), you must call it by including the parentheses. If you reference it without the parentheses, you are referencing the actual function itself (rather than the result of the function), and turing can not treat class subprograms as first-class members (i.e. they cannot be subprogram variables or passed as arguments). So, in short, put parentheses next to the isHungry call or define isHungry without parentheses. |
Author: | corriep [ Sun Apr 05, 2009 1:54 pm ] |
Post subject: | RE:Class subprograms cannot be subprogram variables |
I have run into this problem before also. There is no real work-around but in your case you could just make the hungry variable public instead of using a function to access it |
Author: | richcash [ Sun Apr 05, 2009 2:55 pm ] | ||||
Post subject: | Re: Class subprograms cannot be subprogram variables | ||||
corriep wrote: I have run into this problem before also. There is no real work-around but in your case you could just make the hungry variable public instead of using a function to access it
There is no limitation for what the OP is trying to do. He forgot the parentheses in the function call, it is the same as doing this, which will also give you an error:
The limitation you're talking about is trying to use a class subprogram as a subprogram variable or subprogram argument. That is not what the OP is doing, but the compiler thinks that is what he's doing since he forgot the parentheses (and his function is a class subprogram). Just do this :
|