www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Problems with static elements

reply Marco Falda <Marco_member pathlink.com> writes:
I have problems when compiling this code:

module VincoloPPF;

private import VincoloMF;

class VincoloPPF {
static int c1 = 0;
public static void C1()
{
c1 = 1;
return;
}

this()
{
VincoloMF.C();
}
}

module VincoloMF;

private import VincoloPPF;

class VincoloMF {
static int c = 0;

public static void C()
{
c = 0;
return;
}

this()
{
VincoloPPF.C1();
}
}

DMD (0.141, invoked as dmd VincoloMF.d VincoloPPF.d) says: 
VincoloMF.d(15): undefined identifier module VincoloPPF.Create
VincoloMF.d(15): function expected before (), not module VincoloPPF.Create of
type void
VincoloPPF.d(15): undefined identifier module VincoloMF.Create
VincoloPPF.d(15): function expected before (), not module VincoloMF.Create of
type void

What is wrong in the code? How can I rewrite it? Thank you.
Jan 29 2006
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Marco Falda" <Marco_member pathlink.com> wrote in message 
news:drio81$2rt7$1 digitaldaemon.com...
I have problems when compiling this code:

 module VincoloPPF;

 private import VincoloMF;

 class VincoloPPF {
 static int c1 = 0;
 public static void C1()
 {
 c1 = 1;
 return;
 }

 this()
 {
 VincoloMF.C();
 }
 }

 module VincoloMF;

 private import VincoloPPF;

 class VincoloMF {
 static int c = 0;

 public static void C()
 {
 c = 0;
 return;
 }

 this()
 {
 VincoloPPF.C1();
 }
 }

 DMD (0.141, invoked as dmd VincoloMF.d VincoloPPF.d) says:
 VincoloMF.d(15): undefined identifier module VincoloPPF.Create
 VincoloMF.d(15): function expected before (), not module VincoloPPF.Create 
 of
 type void
 VincoloPPF.d(15): undefined identifier module VincoloMF.Create
 VincoloPPF.d(15): function expected before (), not module VincoloMF.Create 
 of
 type void

 What is wrong in the code? How can I rewrite it? Thank you.
I'm guessing that you've renamed the Create functions to C() somewhere between the time you got the error and the time you posted. The problem is that you've named your classes the same as your modules, so writing VincoloPPF.C() means that the compiler is looking for a function named C() at the module level in VincoloPPF.d. Try VincoloPPF.VincoloPPF.C() instead. If this irritates you, try renaming your module (make it all lowercase, for example, since that's kind of a convention in D). That way, when you write VincoloPPF.C(), it will use the class instead of the module.
Jan 29 2006
parent Marco Falda <Marco_member pathlink.com> writes:
Thank you very much; I changed the names of the modules to lowercase and now the
code is right. 


P.S.: yes, I renamed the function "Create" in "C" in order to avoid possible
reserved words, but I forgot to update the error messages.





In article <driour$2sjj$1 digitaldaemon.com>, Jarrett Billingsley says...
"Marco Falda" <Marco_member pathlink.com> wrote in message 
news:drio81$2rt7$1 digitaldaemon.com...
I have problems when compiling this code:

 module VincoloPPF;

 private import VincoloMF;

 class VincoloPPF {
 static int c1 = 0;
 public static void C1()
 {
 c1 = 1;
 return;
 }

 this()
 {
 VincoloMF.C();
 }
 }

 module VincoloMF;

 private import VincoloPPF;

 class VincoloMF {
 static int c = 0;

 public static void C()
 {
 c = 0;
 return;
 }

 this()
 {
 VincoloPPF.C1();
 }
 }

 DMD (0.141, invoked as dmd VincoloMF.d VincoloPPF.d) says:
 VincoloMF.d(15): undefined identifier module VincoloPPF.Create
 VincoloMF.d(15): function expected before (), not module VincoloPPF.Create 
 of
 type void
 VincoloPPF.d(15): undefined identifier module VincoloMF.Create
 VincoloPPF.d(15): function expected before (), not module VincoloMF.Create 
 of
 type void

 What is wrong in the code? How can I rewrite it? Thank you.
I'm guessing that you've renamed the Create functions to C() somewhere between the time you got the error and the time you posted. The problem is that you've named your classes the same as your modules, so writing VincoloPPF.C() means that the compiler is looking for a function named C() at the module level in VincoloPPF.d. Try VincoloPPF.VincoloPPF.C() instead. If this irritates you, try renaming your module (make it all lowercase, for example, since that's kind of a convention in D). That way, when you write VincoloPPF.C(), it will use the class instead of the module.
Jan 29 2006