PC Review


Reply
Thread Tools Rate Thread

How can 1 use one in 2 forms?

 
 
Allen
Guest
Posts: n/a
 
      25th Sep 2009
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

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      25th Sep 2009
On Sep 25, 2:24Â*am, "Allen" <allen_m...@yahoo.com> 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.
 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      25th Sep 2009
"Allen" <(E-Mail Removed)> wrote in
news:13283485-258F-4DB6-A488-(E-Mail Removed):

> 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! |
*******************************************
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      27th Sep 2009
On Sep 24, 8:24Â*pm, "Allen" <allen_m...@yahoo.com> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I have a million questions - forms, forms, forms Cristy Microsoft Outlook Form Programming 1 1st Oct 2008 06:41 PM
Windows Forms - Opening forms within forms Dan Tallent Microsoft C# .NET 20 27th Aug 2008 06:25 PM
PDF forms filling with ASP.NET, interactive forms, fill and write to database (iText or FDF Toolkit or ...) Toni Pohl Microsoft ASP .NET 1 10th Aug 2008 02:40 PM
Outlook 2003 - Forms Icon On toolbar doesn't list any forms =?Utf-8?B?S2ltLmluLkRlbnZlcg==?= Microsoft Outlook Form Programming 8 28th Jul 2006 04:35 PM
Navigating embedded UserControl forms inside a Windows Forms Panel Emma Middlebrook Microsoft C# .NET 1 25th Oct 2004 02:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:53 PM.