[Help] Using same header in different Form

I have made a header file called Record2.h
Howvere, I can using it in Form1.h and Form2.h in the same time.


// in Form1.h
#include "Record2.h"
#pragma once

namespace AddressBook2 {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
........

// in Form2.h
#include "Record2.h"
#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

namespace AddressBook2 {

public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(int n)
{
InitializeComponent();
.......

Complier will have this error:
1>c:\users\comhk\documents\visual studio 2008\projects\addressbook2\addressbook2\Record2.h(5) : error C2011: 'Record2' : 'class' type redefinition
1> c:\users\comhk\documents\visual studio 2008\projects\addressbook2\addressbook2\Record2.h(5) : see declaration of 'Record2'
1>c:\users\comhk\documents\visual studio 2008\projects\addressbook2\addressbook2\Form1.h(200) : error C2027: use of undefined type 'Record2'
1> c:\users\comhk\documents\visual studio 2008\projects\addressbook2\addressbook2\Record2.h(5) : see declaration of 'Record2'
1>c:\users\comhk\documents\visual studio 2008\projects\addressbook2\addressbook2\Form1.h(200) : fatal error C1903: unable to recover from previous error(s); stopping compilation
1>Generating Code...

So, how can I solve this problem?
Sorry for my poor English.
Try not to include header files inside of header files, instead include header files that are needed for other header files in your main.cpp file before the include for the other header file.
Topic archived. No new replies allowed.