0

First of all, I am using Visual Studio 2010 and I'm trying to write in C++. :p

Here is my question.

Let's say i define a String in Form1, in my case this:

String^ serverlogin="datasource=;port=;username=;password=";

and i want to use it across ALL my forms, what should I do?

I think that this should be defined in public but then I don't know how to access it. :/

I tried to call it in Form2 with this:

String^ movedvar=Form1::serverlogin;

but it didn't worked...

Thanks in advance for your help!

  • possible duplicate of [How do I share a variable between source files in C? With \`extern\`, but how?](http://stackoverflow.com/questions/1433204/how-do-i-share-a-variable-between-source-files-in-c-with-extern-but-how) – Howli May 22 '14 at 08:28
  • Check this answer which explains how to declare global variables correctly: http://stackoverflow.com/questions/1433204/how-do-i-share-a-variable-between-source-files-in-c-with-extern-but-how – jRobin May 07 '14 at 05:38
  • thank you for your answer! I managed to make it work with integers, but it doesn't work with system strings (String). Any ideas? – sakis_the_fraud May 07 '14 at 06:14
  • Sakis, the caret on your variable declaration might be preventing your code from working. I read a bit about it and it seems adding the ^ symbol after String turns your variable into a managed one. Try removing the caret or declaring your variable in its own class as a non-static member if you want to keep it. – jRobin May 07 '14 at 06:40
  • I tried without the caret with no success. I'm getting crazy with this, I managed it to work with int, double and std::string but it won't work with the System String! :@ – sakis_the_fraud May 07 '14 at 06:54

0 Answers0