Click here to Skip to main content
16,010,268 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
ArrayList output = gcnew ArrayList();// as public declaration


this output should be accessed by the functions repeatedly like

function1();

int main(string^ args)
{
  function(string);
}

function1(string^ input)
{
  output->Add(string);
}


in VC++ 2008 \CLR console application
I received error code as c3145.
Posted
Updated 2-Mar-11 20:19pm
v2
Comments
Pravin Patil, Mumbai 3-Mar-11 2:19am    
Edit: Added pre code tags, minor spelling.

Refer to this table: http://connect.microsoft.com/VisualStudio/feedback/details/100163/c-cli-access-modifiers-are-not-consistent[^].

The difference between public and internal is this: public is visible from outside of declaring assembly (by any referencing assembly as well), internal visibility is limited by declaring assembly.

Your problem is quite different: error message c3145 reads: "'object' : global or static variable may not have managed type 'type'".

Why didn't you post the error message in first place? See http://msdn.microsoft.com/en-us/library/by40z94e.aspx[^].

You did not even show the line of code causing error message. Is it the first line in your code? It can be declared only inside ref class or structure. Move it into you class. See the help on error message again (above).

Right now, your code does not make sense though, because you're putting data nowhere, into the collection. Also, don't use ArrayList, use System::Collections::Generic::List. Non-generic collection classes are not needed anymore, after generic is introduced. Non-generic collection classes require type casting in members, who need it?

—SA
 
Share this answer
 
v4
Comments
OriginalGriff 3-Mar-11 3:07am    
I'm not sure that access modifiers are his problem: the error number leads to something much more specific!
Sergey Alexandrovich Kryukov 3-Mar-11 10:28am    
This is incredible: the error message is "'object' : global or static variable may not have managed type 'type'"; OP did not show the message but probably decided it's access problem!
Thank you, Griff.
--SA
Sergey Alexandrovich Kryukov 3-Mar-11 10:42am    
Thank you for the note; I updated the Answer with explanation of error.
--SA
You can't declare .NET variables as global objects: it isn't supported: that's what the error is saying:
Error C3145 cannot declare a global or static managed type object or an _gc pointer


The problem is that .NET does not have a concept of global variables, only class scope. To get around this, you can declare it as a static member of a Globals class:

public ref class Globals
   {
   public:
      static ArrayList output = gcnew ArrayList();
   }


As usual, MSDN comes to the rescue: error C3145 global or static managed type object or an _gc pointer[^]

[edit]Forgot the code block :-O - OriginalGriff[/edit]
 
Share this answer
 
v2
Comments
Dalek Dave 3-Mar-11 3:52am    
Good Answer.
Sergey Alexandrovich Kryukov 3-Mar-11 10:45am    
All correct, 5,
--SA
The M A R S 15-Mar-11 5:26am    
its working good thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900