namespace cannot contain a class with the same name
Posted: Thu Jul 01, 2010 3:26 pm
First post... I didnt find a way to report an issue (probably because it is already late... sleepy lol) but here we go:
If I have the following program where I define a namespace called GreetProgram and also a Class called GreetProgram I receive the compiler error shown below. In the topic of Namespaces it doesn't mention that you should not name a class the same as the namespace thats why I'm creating this post. If I change the name of the namespace or the class it works.
This program will be my next blog post: called OO Hello World in Cobra (you can have a look in http://carlosqt.blogspot.com/ )
N:\CLR\Cobra\Cobra\Cobra\bin>cobra.exe hellocobra.cobra
n:\CLR\Cobra\Cobra\Cobra\bin\hellocobra.cobra(17): error: The type name "Greet"
does not exist in the type "GreetProgram.GreetProgram"
Compilation failed - 1 error, 0 warnings
Not running due to errors above.
If I have the following program where I define a namespace called GreetProgram and also a Class called GreetProgram I receive the compiler error shown below. In the topic of Namespaces it doesn't mention that you should not name a class the same as the namespace thats why I'm creating this post. If I change the name of the namespace or the class it works.
This program will be my next blog post: called OO Hello World in Cobra (you can have a look in http://carlosqt.blogspot.com/ )
use System
namespace GreetProgram
class Greet
var name as String
cue init(name as String)
base.init
.name = name[0].toString.toUpper + name[1:]
def salute
print "Hello [.name]!"
#Greet the world!
class GreetProgram
def main is shared
g = Greet("world")
g.salute
N:\CLR\Cobra\Cobra\Cobra\bin>cobra.exe hellocobra.cobra
n:\CLR\Cobra\Cobra\Cobra\bin\hellocobra.cobra(17): error: The type name "Greet"
does not exist in the type "GreetProgram.GreetProgram"
Compilation failed - 1 error, 0 warnings
Not running due to errors above.