BitArray use (System.Collections)

G

Guest

I was so happy to find the BitArray class.

Until I 'cut and pasted' the following sample code from Visual Studio's help:

#using <mscorlib.dll>
#using <system.dll>

using namespace System;
using namespace System::Collections;

I got the following error repeated 4 times:

fatal error C1190: managed targeted code requires '#using <mscorlib.dll>'
and '/clr' option

Sorry if this is a 'newbie' question, but has anyone seen this before and
know what to do? Can I buy a vowel? Is Visual Studio telling me I have to
build my OS dll's with the '/clr' option for heaven's sake?! Obviously I
can't do that.
 
G

Guest

Guess I was brain dead today. I had the #using... in my '.h' file instead of
my '.cpp' file.
 
G

Guest

VS sample code below won't compile in my app:

#using <mscorlib.dll>
#using <system.dll>

using namespace System;
using namespace System::Collections;

I get:

fatal error C1190: managed targeted code requires '#using <mscorlib.dll>'
and '/clr' option

Sad when the sample code won't even compile. I searched the help dox, my
project and options file for some clue about what was wrong. Nada.

Can anyone point me in the right direction? Thanks in advance.
 
G

Guest

I'm back to square one.

Put this sampe code in my app:

#using <mscorlib.dll>
#using <system.dll>

using namespace System;
using namespace System::Collections;

Got compile errors:

fatal error C1190: managed targeted code requires '#using <mscorlib.dll>'
and '/clr' option

Any ideas? It's awful when the sample code won't compile (nor give any
explanation where to look)
 
G

Guest

Maybe I'm on the path now that I've figure out "/clr" option means COMPILE
option. (MS you might've mentioned the word 'compile' in your error message,
considering the plethora of types of options there are in VS.)

Of course the "/clr" compile switch is not compatible with (I've yet to
determine how many) other compile switches. Thanks again MS for making me
find them one at a time. Sad!

I'm switching to Sun java.
 
G

Guest

Well, I'll be d*mn*d.

I got all the right compile, etc switches and tried again...AND IT STILL
WON'T COMPILE!

BitArray *smp = new BitArray(5);

generates error: "'Systems::Collections::BitArray': placement arguments not
allowed while creating instances of managed classes"

How f*ed up is that message? Could it be more cryptic or meaningless or
less helpful?! How pathetic. I'm beginning to remember why I quit using VS
for so long. Got tired of the frustration.

This has to be MS's way of marketing training (and generating the $99 a hit
per question income). They should just post a big banner on their splash
screen "Go ahead and try to use our arcane spaghetti IDE w/o our
training.....bwahahaha <-evil laugh sound track".
 
G

Guest

Summary of my experience using the BitArray class in C++ from MSVS.NET:

#using <mscorlib.dll>
#using <system.dll>

using namespace System;
using namespace System::Collections;

will only work if compiler option "/clr" is present AND compiler options
"/z1", "/ctl1" and a few other are NOT present. They can be enabled/disabled
from the 'Project' menu under the 'Properties' choice (except of course for
/clr which I only found referenced in the arcane help section, but nowhere in
MSVS...fortunately it can be typed in manually). Sorry if I forgot a few of
the incompatible switches. You can find them...one at a time...by compiling,
getting a rebuke, removing the offender from the compile option list...and
repeat.

IN ADDITION:
"
// Creates and initializes several BitArrays.
BitArray* myBA1 = new BitArray( 5 );
"
(quote from the IDE sample code)

DOES NOT COMPILE. You get some arcane worthless message that is not at all
helpful. Also:

BitArray* myBA1;
myBA1 = new BitArray( 5 );

fails with the same error.

This compiles:

BitArray* myBA1;
myBA1->set_Length( 5);

but will SURELY fail at runtime...or will it?...as no memory was ever
allocated...or was it?!

WTF?
 
D

Daniel O'Connell [C# MVP]

IN ADDITION:
"
// Creates and initializes several BitArrays.
BitArray* myBA1 = new BitArray( 5 );
"
(quote from the IDE sample code)

DOES NOT COMPILE. You get some arcane worthless message that is not at
all
helpful. Also:

BitArray* myBA1;
myBA1 = new BitArray( 5 );

fails with the same error.

This compiles:

BitArray* myBA1;
myBA1->set_Length( 5);

but will SURELY fail at runtime...or will it?...as no memory was ever
allocated...or was it?!

WTF?

Ok, lets start at the beginning. In your first post you said you were
building OS dlls. I assume you are working on a personal OS. In which case
the CLR and the BitArray class are not ideal, since that is linked to the
CLR and I imagine implementing the whole of the CLR isn't high on your wish
list(that potentially means a huge number of classes, including BItArray,
along with a JIT, a GC, and so on. The Mono project might help, but thats
still alot of work). You'd do better to use pure C++ templates such as those
available in the boost project(www.boost.org,) assuming they fit your
licensing requirements.

Second, what version of Visual Studio(or Visual C++) are you using? There
are two different C++ dialects for managed code, MC++(or Managed Extensions
for C++) which has been available since VS2002(IIRC) and CLI/C++ which
debuted with VS2005. Both work different than standard C++ when working with
managed classes and will require a little learning to use properly. MC++
especially is a little tricky.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top