CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: two Main()

  1. #1
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822

    two Main()

    hi i have a file..
    and another both in the same project...
    one class is being derieved form another
    but the prob is : i am getting error
    CsDateInheritance.exe' has more than one entry point defined: 'CsDateConstructors.Main()'
    CsDateInheritance.exe' has more than one entry point defined: 'CsDateInheritance.Main()'
    i have the above two files and both have main..but one is derieved from another....
    why am i getting this error??
    pls help...
    tks...
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    170

    Re: two Main()

    Originally posted by Joseph_R_Thomas
    i have the above two files and both have main..but one is derieved from another....
    why am i getting this error??
    pls help...
    tks...
    Hi, what I would is remove the Main() methods from both classes, then create a third class that does not inherit from anything and add a Main() method there.

    Something like this:

    Code:
    public class CsDateConstructors
    {
    }
    
    public class CsDateInheritance : CsDateConstructors
    {
    }
    
    public class MyMain
    {
       static void Main(string[] args)
       {
          CsDateInheritance myInheritence = new CsDateInheritance();
       }
    }
    Jim
    I am scifi

  3. #3
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822
    i dun wanna do that...i am following a example and i am using the same exact codes...
    the example runs fine/......
    but mine doesnt./..
    every word in the two files are same...
    still mine doesnt run...
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

  4. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    170
    Can you post your code so I can take a look?

    Jim
    Last edited by xucaen; October 22nd, 2003 at 10:24 AM.
    I am scifi

  5. #5
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822
    Code:
    using System;
    
    class CsDateConstructors
    {
    	public static void Main()
    	{
    		try
    		{
    			Date mydate = new Date(2001, 8, 29);
    
    			Console.WriteLine("Day of year = " + mydate.DayOfYear);
    		}
    		catch (Exception exc)
    		{
    			Console.WriteLine(exc);
    		}
    	}         
    }
    class Date
    {
    	// Fields
    	int year;
    	int month;
    	int day;
    	static int[] MonthDays = new int[] {   0,  31,  59,  90, 120, 151,
    										   181, 212, 243, 273, 304, 334 };
    
    	// Constructors
    	public Date()
    	{
    		Year = 1600;
    		Month = 1;
    		Day = 1;
    	}
    	public Date(int year, int month, int day)
    	{
    		if ( (month == 2 &&  IsLeapYear(year) && day > 29) ||
    			(month == 2 && !IsLeapYear(year) && day > 28) ||
    			((month == 4 || month == 6 || 
    			month == 9 || month == 11) && day > 30))
    		{
    			throw new ArgumentOutOfRangeException("Day");
    		}
    		else
    		{
    			Year  = year;
    			Month = month;
    			Day   = day;
    		}
    	}
    	// Properties
    	public int Year
    	{
    		set
    		{
    			if (value < 1600)
    				throw new ArgumentOutOfRangeException("Year");
    			else
    				year = value;
    		}
    		get
    		{
    			return year;
    		}
    	}
    	public int Month
    	{
    		set
    		{
    			if (value < 1 || value > 12)
    				throw new ArgumentOutOfRangeException("Month");
    			else
    				month = value;
    		}
    		get
    		{
    			return month;
    		}
    	}
    	public int Day
    	{
    		set
    		{
    			if (value < 1 || value > 31)
    				throw new ArgumentOutOfRangeException("Day");
    			else
    				day = value;
    		}
    		get
    		{
    			return day;
    		}
    	}
    	public int DayOfYear
    	{
    		get
    		{
    			return MonthDays[month - 1] + day + 
    				(month > 2 && IsLeapYear(year) ? 1 : 0);
    		}
    	}
    	// Method
    	public static bool IsLeapYear(int year)
    	{
    		return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
    	}
    }
    Code:
    using System;
    
    class CsDateInheritance
    {
    	public static void Main()
    	{
    		DatePlus birth = new DatePlus(1953, 2, 2);
    		DatePlus today = new DatePlus(2001, 8, 29);
    
    		Console.WriteLine("Birthday = {0}", birth);
    		Console.WriteLine("Today = " + today);
    		Console.WriteLine("Days since birthday = {0}", today - birth);
    	}         
    }
    class DatePlus: Date
    {
    	public DatePlus() {}
    	public DatePlus(int year, int month, int day): base(year, month, day) {}
    
    	public int DaysSince1600
    	{
    		get
    		{
    			return 365 * (Year - 1600) + 
    				(Year - 1597) / 4 -
    				(Year - 1601) / 100 +
    				(Year - 1601) / 400 + DayOfYear;
    		}
    	}
    	public override string ToString()
    	{
    		string[] str = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
    						   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
    
    		return String.Format("{0} {1} {2}", Day, str[Month - 1], Year);
    	}
    	public static int operator -(DatePlus date1, DatePlus date2)
    	{
    		return date1.DaysSince1600 - date2.DaysSince1600;
    	}
    }
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

  6. #6
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    170
    I think you want to have three projects, one containing the CsDateConstructors class, another project containing the CsDateInheritance class and a third containing the Date classes. Then to run one and not the other you simply set it as the startup project. This way all of the Main() methods are seperate

    I've seperated your projects so you can see how it is done. The Date classes are compiled as a Class Library which means only a .DLL is created. The other two are compiled as Console Applications and each creates an executable (.exe). In order to use this .Dll, you need a using statement (which I have put in for you) and you need to add a reference to the .Dll for each project that will be using it. You do this by first setting a project as the startup project, then go to the Project Menu and select the Add Reference. Then select the .Dll you wan to use and select OK. I've done this for you in the attached project.

    You'll get used to doing this the more you do it.

    Your Date classes work very well, great job!

    I hope this helps. Let me know if you have any proplems or questions.

    Jim
    Attached Files Attached Files
    I am scifi

  7. #7
    Join Date
    Dec 2002
    Posts
    1,050
    More than one main requires that you specify the startup
    object.

    From the DevStudio menu

    Project/ "My Project" properties.

    On the properties property sheet; common options. Look for
    'Startup Object" and set it.

  8. #8
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024
    If you build it from command line, then you can use one of the compiler options "main"

    Ex:

    csc /t:exe /out:test.exe /main:ConsoleApplication13.Class1 Class1.cs Class2.cs

    Class1 and Class2 both have main method declared in them.

  9. #9
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822
    i am not using command line
    m using visual studio.net
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

  10. #10
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822
    Originally posted by mdmd
    More than one main requires that you specify the startup
    object.

    From the DevStudio menu

    Project/ "My Project" properties.

    On the properties property sheet; common options. Look for
    'Startup Object" and set it.
    its in the same project.......
    both the mains are in the same project....
    just different files....
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

  11. #11
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822
    well....i think i should probably post the project...
    maybe that will say better than my words...
    i need to get the "Project2" working....
    tks for help...
    Attached Files Attached Files
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

  12. #12
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    170
    Originally posted by Joseph_R_Thomas
    its in the same project.......
    both the mains are in the same project....
    just different files....
    then the only way to do it is to comment out one of the Main methods so that the other can run. The language simply does not allow two main methods and there's nothing you can do to change that.

    Jim
    I am scifi

  13. #13
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    170
    Originally posted by Joseph_R_Thomas
    well....i think i should probably post the project...
    maybe that will say better than my words...
    i need to get the "Project2" working....
    tks for help...
    did you download the project I attached for you? I got both projects to work there.

    Jim
    I am scifi

  14. #14
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822
    i cannot open it...my vs.net version is old...
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

  15. #15
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822
    nope...i have a version that is exactly same codes and its working fine...
    there's gotta be some other trick...
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured