Page 2 of 3

Re: public, static & friends

PostPosted: Sat Feb 09, 2008 12:32 pm
by Charles
Can you reply again and use the "Upload attachment" to give us your source?

Re: public, static & friends

PostPosted: Sat Feb 09, 2008 12:34 pm
by RichS
It seems the property must be shared as well.

Try sharing both definitions.

(Chuck, I'll upload the source when I find the right button.)

Re: public, static & friends

PostPosted: Sat Feb 09, 2008 12:36 pm
by neuruss
Here it goes (it's a .txt file, because .cobra is not allowed)

Re: public, static & friends

PostPosted: Sat Feb 09, 2008 12:41 pm
by neuruss
RichS wrote:It seems the property must be shared as well.

Try sharing both definitions.

(Chuck, I'll upload the source when I find the right button.)


I tried placing "var _lista = Lista<of Dude>()" and "pro lista from var" in the shared block, but I got this error:

hello2.cobra(35): error: Static member "Dude.Lista.get" cannot be accessed with
an instance reference; qualify it with a type name instead
hello2.cobra(5): warning: (Location of symbol related to previous error)
Compilation failed - 1 error, 1 warning
Not running due to errors above.

Re: public, static & friends

PostPosted: Sat Feb 09, 2008 12:41 pm
by Charles
I don't see it...

Re: public, static & friends

PostPosted: Sat Feb 09, 2008 12:44 pm
by neuruss
Please just forget it!
It was a line of code that I forgot to delete...

print x.lista


Sorry guys!

Re: public, static & friends

PostPosted: Sat Feb 09, 2008 12:46 pm
by neuruss
I believed the attachment didn't work...here it goes again.

Re: public, static & friends

PostPosted: Sat Feb 09, 2008 12:52 pm
by Charles
I'll have to investigate attachments at some point. I'll be of the forums for awhile now to work on Cobra.

Re: public, static & friends

PostPosted: Wed Feb 13, 2008 6:29 pm
by neuruss
Sorry guys, but this is still not clear to me...
I read in another thread that the "public" keyword is recognized in Cobra 0.7.2.
Indeed, this compiled:

var _name as String is public


However, this member doesn't behave as public...
So I'm back to my original question:
Is it possible to declare a member as public (without having to create a property from it?)

neuruss

Re: public, static & friends

PostPosted: Wed Feb 13, 2008 8:47 pm
by khjklujn
In the following code, _classVariable is freely accessible to anyone (including Bob) by using Bob._classVariable, and the value will be the same for everyone.

_instanceVariable is freely accessible to anyone who has an instance of Bob, but the value will depend on the particular instance.

class Bob
shared
var _classVariable as String is public

var _instanceVariable as String? is public

class Program
def main is shared
Bob._classVariable = "Yo"

a = Bob()
a._instanceVariable = "baby"

b = Bob()
b._instanceVariable = "and then some more"

print Bob._classVariable
print a._instanceVariable
print b._instanceVariable