Help!
dynamic.h
#pragma once
#include "static.h"
#include
"stdafx.h"using
namespace System::Collections;public
ref class testit {public
: testit(array<city^>^City){
System::Diagnostics::Debug::WriteLine(City[1]->cityID);
}
};
static.h
#pragma
once//#include "dynamic.h" (works when not included)
ref
struct city{
int cityID;String ^ cityName;
};
Form1.h
#include
"static.h"#include "dynamic.h"
public ref class Form1 : public System::Windows::Forms::Form
{
....
private: array<city^> ^City;
}
void
InitializeComponent(void){
....
this
->City = gcnew array<city^>(800);City[1] =
gcnew city(); // testCity[1]->cityID=100; // test
System::Diagnostics::Debug::WriteLine(City[1]->cityID);
testit ^ test =
gcnew testit(City);}
******
when the form1 initialises, this works fine
(i get 100 twice)
However, when i include 'dynamic.h' from 'static.h', the compiler bombs out
dynamic.h(9) : error C2065: 'city' : undeclared identifier
With the code shown, I don't need to do this include, but with my main project, I need to cross-reference all the time between the static and dynamic headers.
This is confusing the hell out of me. Any ideas would be much appreciated
I am a beginner and if I am doing this a really silly way, then any guidance on a better way would be gratefully received.
In the code above, by the way, I am confused further by having to initialise an instance of City[1] (City[1] = gcnew city(); ) - I thought with a struct I should be able to directly access City[1].cityID ---

Another example of my problem with structs...
omar 14492
this looks to me like a quirk in the VS2005 beta compiler. if i move my objects around between the static & dynamic header, i can solve the problem without any code changes at all.
SteveTri
Arvid
From what I understand, one of your problems is with cross-referencing.
It doesn't really appear in your sample because static.h doesn't reference any type from dynamic.h...
If you need to cross-reference between classes in C++, you may do the following :
(I only have a VS.NET 2003 at hand so this will be old managed style)
ClassA.h
__gc class ClassB; // Tell the compiler that ClassB is an object type.
__gc class ClassA
{
ClassB* m_hBReference; // Now you can declare a reference to a ClassB object.
};
ClassB.h
#include "ClassA.h"
__gc class ClassB
{
// You included "ClassA.h" so no problem to reference a ClassA object.
ClassA* m_hAReference;
};
Afterwards, just include "ClassB.h" wherever you need objets from either header.
main.cpp
#include "stdafx.h"
#include "ClassB.h"
#using <mscorlib.dll>
using namespace System;
void _tmain()
{
ClassA* hA = __gc new ClassA;
ClassB* hB = __gc new ClassB;
}
I hope this can help you.