Click here to Skip to main content
15,916,527 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralHelp with linker errors Pin
l0t3k4-Mar-05 3:43
l0t3k4-Mar-05 3:43 
GeneralVisual Studio IDE Pin
Gabor Kalman4-Mar-05 2:47
Gabor Kalman4-Mar-05 2:47 
GeneralI'm searching for Visual C++ Books Pin
fracco4-Mar-05 1:16
fracco4-Mar-05 1:16 
GeneralRe: I'm searching for Visual C++ Books Pin
Jetli Jerry4-Mar-05 2:35
Jetli Jerry4-Mar-05 2:35 
GeneralRe: I'm searching for Visual C++ Books Pin
ur_unholyness4-Mar-05 7:29
ur_unholyness4-Mar-05 7:29 
GeneralRe: I'm searching for Visual C++ Books Pin
Anand for every one4-Mar-05 19:39
Anand for every one4-Mar-05 19:39 
GeneralSending a digitally signed email Pin
Muhammad Irfan Azam4-Mar-05 1:04
Muhammad Irfan Azam4-Mar-05 1:04 
Questionglobally scoped array of objects? Pin
baxybaxy4-Mar-05 0:51
baxybaxy4-Mar-05 0:51 
hi everyone. i'm hoping there's a genius out there who can help me with this

bit of a beginner here with C++. I'm using .net 2.0 / VS 2005 Beta (for my sins!)

i have a rather basic problem, which i cannot seem to resolve.

i have a managed class "city" (definitions below)

i have a function to load an external XML file (selected by the user), which creates a managed array City, as follows (the int "numberofcities" is also read from the file)

array<city^>^City = gcnew array<city^>(numberofcities);

each object City[0], City[1], City[2] etc is then created as I loop through the XML city file, using

City[rowcount] = gcnew city(...,...,.... )

obviously, i don't know the size of the array or the contents until the file is selected by the user and the XML is processed.

All well and good so far. I can play with the array within the file loading function and I'm happy. But then the City array of objects is of local scope to the function loading the XML, and I want to be able to access this array elsewhere in the program

for example, i have a function where i draw the cities on a map, and want to use something like:
double longitude = City[1]->lng;
double latitude = City[2]->lat;
and so on.

so after the long winded introduction: my question is -- how can i make City available to other functions outside of the scope where it was loaded?

i have had a few people make suggestions, but no-one has come up with something workable so far.

i heard about:
1. using native arrays rather than .net arrays -- but then i can't include system::strings in the class
2. defining a "wrapper class" - have only found references to this regarding .COM objects ? i confess, i don't know where to start.
3. using a singleton object and instances (?) : again, no clue
4. using a pin pointer; (but the pin pointer is only a local scope variable also?) and anyway i don't know if it works
5. passes the array from function to function. i'm not sure i can make that work either. also, there is more than one array loaded alongside City.
6. don't use arrays of objects, use XML connection directly in each function. could work, but i would lose all the benefits of being able to manipulate objects (for example, i will have a method for city to allocate all the demand from city 1 to city 2)

i would really appreciate someone giving either a detailed idea of how to address this... or at the least maybe giving some sort of indication of which if any of the above suggestions is worth me looking in to in more depth

thanks everyone!


//////////////////

public ref class city
{
public: int cityID;
String ^cityName;
String ^ countryID;
String ^ countryName;
double lng, lat;
double dailydemand;
double annualdemand;

//constructor

public: city() {
dailydemand = 0;
annualdemand = 0;
}

public: city(int cID,String ^ cName,String ^ coID,String ^ coName,double ln,double la)
{
cityID=cID;
cityName=cName;
countryID=coID;
countryName=coName;
lng=ln;
lat=la;
}
};
AnswerRe: globally scoped array of objects? Pin
Steen Krogsgaard4-Mar-05 4:14
Steen Krogsgaard4-Mar-05 4:14 
GeneralRe: globally scoped array of objects? Pin
Chris Meech4-Mar-05 5:42
Chris Meech4-Mar-05 5:42 
GeneralRe: globally scoped array of objects? Pin
Steen Krogsgaard6-Mar-05 21:05
Steen Krogsgaard6-Mar-05 21:05 
QuestionWhat is the Mystery behind Release Folder ? Pin
zahid_ash4-Mar-05 0:36
zahid_ash4-Mar-05 0:36 
AnswerRe: What is the Mystery behind Release Folder ? Pin
jan larsen4-Mar-05 1:42
jan larsen4-Mar-05 1:42 
GeneralRe: What is the Mystery behind Release Folder ? Pin
aritosteles5-Mar-05 13:53
aritosteles5-Mar-05 13:53 
Generaltext setting in list control Pin
deldeep3-Mar-05 23:39
deldeep3-Mar-05 23:39 
GeneralRe: text setting in list control Pin
David Crow4-Mar-05 2:59
David Crow4-Mar-05 2:59 
GeneralRe: text setting in list control Pin
deldeep4-Mar-05 20:45
deldeep4-Mar-05 20:45 
GeneralRe: text setting in list control Pin
David Crow7-Mar-05 3:20
David Crow7-Mar-05 3:20 
GeneralRe: text setting in list control Pin
deldeep7-Mar-05 17:39
deldeep7-Mar-05 17:39 
GeneralCREATE PROCESS Pin
sunit53-Mar-05 22:59
sunit53-Mar-05 22:59 
GeneralRe: CREATE PROCESS Pin
Jetli Jerry4-Mar-05 0:46
Jetli Jerry4-Mar-05 0:46 
GeneralRe: CREATE PROCESS Pin
sunit54-Mar-05 2:13
sunit54-Mar-05 2:13 
GeneralRe: CREATE PROCESS Pin
sunit54-Mar-05 2:15
sunit54-Mar-05 2:15 
GeneralRe: CREATE PROCESS Pin
David Crow4-Mar-05 3:05
David Crow4-Mar-05 3:05 
GeneralSet background colour on a CDateTimeCtrl Pin
roccap3-Mar-05 22:46
roccap3-Mar-05 22:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.