Forums

public, static & friends

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Re: public, static & friends

Postby Charles » Sat Feb 09, 2008 12:32 pm

Can you reply again and use the "Upload attachment" to give us your source?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: public, static & friends

Postby RichS » Sat Feb 09, 2008 12:34 pm

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.)
Last edited by RichS on Sat Feb 09, 2008 12:36 pm, edited 1 time in total.
RichS
 
Posts: 8

Re: public, static & friends

Postby neuruss » Sat Feb 09, 2008 12:36 pm

Here it goes (it's a .txt file, because .cobra is not allowed)
neuruss
 
Posts: 23

Re: public, static & friends

Postby neuruss » Sat Feb 09, 2008 12:41 pm

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.
neuruss
 
Posts: 23

Re: public, static & friends

Postby Charles » Sat Feb 09, 2008 12:41 pm

I don't see it...
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: public, static & friends

Postby neuruss » Sat Feb 09, 2008 12:44 pm

Please just forget it!
It was a line of code that I forgot to delete...

print x.lista


Sorry guys!
neuruss
 
Posts: 23

Re: public, static & friends

Postby neuruss » Sat Feb 09, 2008 12:46 pm

I believed the attachment didn't work...here it goes again.
neuruss
 
Posts: 23

Re: public, static & friends

Postby Charles » Sat Feb 09, 2008 12:52 pm

I'll have to investigate attachments at some point. I'll be of the forums for awhile now to work on Cobra.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: public, static & friends

Postby neuruss » Wed Feb 13, 2008 6:29 pm

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
neuruss
 
Posts: 23

Re: public, static & friends

Postby khjklujn » Wed Feb 13, 2008 8:47 pm

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
khjklujn
 
Posts: 29

PreviousNext

Return to Discussion

Who is online

Users browsing this forum: No registered users and 92 guests

cron