How can 1 use one in 2 forms?

Discussion in 'ASP .Net' started by Allen, Sep 25, 2009.

  1. Allen

    Allen Guest

    Below are 4 forms. Namely: Form1, EmployeeID, AboutBox and
    EnterEmployeeName. I made a class to help in open, write and read from
    files called Time. I managed to declare class Time in EmployeeID space, but
    could not declare it in EnterEmployeeName. In other words, I can declare
    class Time in one space only. I really want to use class Time in both forms
    EmployeeID and EnterEmployeeName. Can anybody tell me why I always get
    error below, every time I run the program? And how can I use the Time class
    in both the above forms?

    1>c:\users\allen\documents\visual studio
    2008\projects\timetracking\timetracking\Time.h(5) : error C2011: 'Time' :
    'class' type redefinition
    1> c:\users\allen\documents\visual studio
    2008\projects\timetracking\timetracking\Time.h(5) : see declaration of
    'Time'
    1>EnterEmployeeName.cpp

    #pragma once
    #include "AboutBox.h"
    #include "EmployeeID.h"
    #include "EnterEmployeeName.h"
    namespace TimeTracking
    {
    using namespace System::Windows::Forms;
    public ref class Form1 : public System::Windows::Forms::Form
    {

    };
    }
    /***************************/
    #pragma once
    #include "Time.h"
    //#include "stdafx.h"
    #using <mscorlib.dll>

    namespace TimeTracking
    {
    public ref class EmployeeID : public System::Windows::Forms::Form
    {
    };
    }
    /***************************/
    #pragma once
    namespace TimeTracking
    {
    public ref class AboutBox : public System::Windows::Forms::Form
    {

    };
    }
    /***************************/
    #pragma once
    #include "stdafx.h"
    //#include "Time.h" //-------------uncomment and get error C2011

    namespace TimeTracking
    {

    public ref class EnterEmployeeName : public System::Windows::Forms::Form
    {

    };
    }
    /***************************/
    using namespace System;
    ref class Time
    {
    };
    /***************************/
    #include "stdafx.h"
    #include "Time.h"
    #using <mscorlib.dll>


    --
    Thanks
    Allen
     
    Allen, Sep 25, 2009
    #1
    1. Advertising

  2. On Sep 25, 2:24 am, "Allen" <> wrote:
    > Below are 4 forms. Namely: Form1, EmployeeID, AboutBox and
    > EnterEmployeeName.  I made a class to help in open, write and read from
    > files called Time.  I managed to declare class Time in EmployeeID space, but
    > could not declare it in EnterEmployeeName.  In other words, I can declare
    > class Time in one space only.  I really want to use class Time in both forms
    > EmployeeID and EnterEmployeeName.  Can anybody tell me why I always get
    > error below, every time I run the program?  And how can I use the Time class
    > in both the above forms?
    >
    > 1>c:\users\allen\documents\visual studio
    > 2008\projects\timetracking\timetracking\Time.h(5) : error C2011: 'Time' :
    > 'class' type redefinition
    > 1>        c:\users\allen\documents\visual studio
    > 2008\projects\timetracking\timetracking\Time.h(5) : see declaration of
    > 'Time'
    > 1>EnterEmployeeName.cpp
    >
    > #pragma once
    > #include "AboutBox.h"
    > #include "EmployeeID.h"
    > #include "EnterEmployeeName.h"
    > namespace TimeTracking
    > {
    >  using namespace System::Windows::Forms;
    >   public ref class Form1 : public System::Windows::Forms::Form
    >  {
    >
    >  };}
    >
    > /***************************/
    > #pragma once
    > #include "Time.h"
    > //#include "stdafx.h"
    > #using <mscorlib.dll>
    >
    > namespace TimeTracking
    > {
    >  public ref class EmployeeID : public System::Windows::Forms::Form
    >  {
    >  };}
    >
    > /***************************/
    > #pragma once
    > namespace TimeTracking
    > {
    >  public ref class AboutBox : public System::Windows::Forms::Form
    >  {
    >
    >  };}
    >
    > /***************************/
    > #pragma once
    > #include "stdafx.h"
    > //#include "Time.h"   //-------------uncomment and get error C2011
    >
    > namespace TimeTracking
    > {
    >
    >  public ref class EnterEmployeeName : public System::Windows::Forms::Form
    >  {
    >
    >  };}
    >
    > /***************************/
    > using namespace System;
    > ref  class Time
    > {};
    >
    > /***************************/
    > #include "stdafx.h"
    > #include "Time.h"
    > #using <mscorlib.dll>
    >
    > --
    > Thanks
    > Allen


    Allen, you are in the wrong group.
     
    Alexey Smirnov, Sep 25, 2009
    #2
    1. Advertising

  3. "Allen" <> wrote in
    news::

    > Below are 4 forms. Namely: Form1, EmployeeID, AboutBox and
    > EnterEmployeeName. I made a class to help in open, write and read
    > from files called Time. I managed to declare class Time in EmployeeID
    > space, but could not declare it in EnterEmployeeName. In other words,
    > I can declare class Time in one space only. I really want to use
    > class Time in both forms EmployeeID and EnterEmployeeName. Can
    > anybody tell me why I always get error below, every time I run the
    > program? And how can I use the Time class in both the above forms?


    I am not a C++ expert, so I would suggest reposting in a C++ group. I can,
    however, tell you WHAT is happening. With the way you are linking Time, you
    are ending up with two links, which is causing the compiler to bomb. As I
    have only hacked C++ in my career, I am not sure what to tell you to get
    past this error, however.

    Peace and Grace,


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    My vacation and childhood cancer awareness site:
    http://www.crazycancertour.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Sep 25, 2009
    #3
  4. Allen

    Richard Guest

    On Sep 24, 8:24 pm, "Allen" <> wrote:
    > Below are 4 forms. Namely: Form1, EmployeeID, AboutBox and
    > EnterEmployeeName.  I made a class to help in open, write and read from
    > files called Time.  I managed to declare class Time in EmployeeID space, but
    > could not declare it in EnterEmployeeName.  In other words, I can declare
    > class Time in one space only.  I really want to use class Time in both forms
    > EmployeeID and EnterEmployeeName.  Can anybody tell me why I always get
    > error below, every time I run the program?  And how can I use the Time class
    > in both the above forms?
    >
    > 1>c:\users\allen\documents\visual studio
    > 2008\projects\timetracking\timetracking\Time.h(5) : error C2011: 'Time' :
    > 'class' type redefinition
    > 1>        c:\users\allen\documents\visual studio
    > 2008\projects\timetracking\timetracking\Time.h(5) : see declaration of
    > 'Time'
    > 1>EnterEmployeeName.cpp
    >
    > #pragma once
    > #include "AboutBox.h"
    > #include "EmployeeID.h"
    > #include "EnterEmployeeName.h"
    > namespace TimeTracking
    > {
    >  using namespace System::Windows::Forms;
    >   public ref class Form1 : public System::Windows::Forms::Form
    >  {
    >
    >  };}
    >
    > /***************************/
    > #pragma once
    > #include "Time.h"
    > //#include "stdafx.h"
    > #using <mscorlib.dll>
    >
    > namespace TimeTracking
    > {
    >  public ref class EmployeeID : public System::Windows::Forms::Form
    >  {
    >  };}
    >
    > /***************************/
    > #pragma once
    > namespace TimeTracking
    > {
    >  public ref class AboutBox : public System::Windows::Forms::Form
    >  {
    >
    >  };}
    >
    > /***************************/
    > #pragma once
    > #include "stdafx.h"
    > //#include "Time.h"   //-------------uncomment and get error C2011
    >
    > namespace TimeTracking
    > {
    >
    >  public ref class EnterEmployeeName : public System::Windows::Forms::Form
    >  {
    >
    >  };}
    >
    > /***************************/
    > using namespace System;
    > ref  class Time
    > {};
    >
    > /***************************/
    > #include "stdafx.h"
    > #include "Time.h"
    > #using <mscorlib.dll>
    >
    > --
    > Thanks
    > Allen


    How about making your other classes sub-classes of Time. Then all
    times public methods would be available to them.

    HTH,
    Richard
     
    Richard, Sep 27, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. M
    Replies:
    0
    Views:
    384
  2. news.frontiernet.net
    Replies:
    6
    Views:
    1,132
    news.frontiernet.net
    Apr 16, 2004
  3. loveNUNO
    Replies:
    2
    Views:
    928
    loveNUNO
    Nov 20, 2003
  4. Merciadri Luca
    Replies:
    4
    Views:
    823
  5. Eric
    Replies:
    2
    Views:
    565
Loading...

Share This Page