Serguei Fedorov
Serguei Fedorov

Reputation: 7923

Multiple Pointers in Fixed(){} initialized with "new" does not work

When I try to initialize a new char* array using fixed while being ilitialized allong side other things, it does not work. The following code is an example of that

fixed (char* buffer = new char[25])
{
     //This works just fine
}; 

fixed (char* origionalPhrase = phrase, char* buffer = new char[25])
{
    //This does not
}

The syntax parser underlines the new char[25] as being "Cannot implicitly convert type 'char[]' to 'char*'". I need both those variables to be initialized as char* arrays. The first variable, origionalPhrase variable initializes just fine. The MSNDN documentation points out that:

fixed (byte* ps = srcarray, pd = dstarray) {...}

will work.

I used this MSDN article.

Upvotes: 2

Views: 4645

Answers (2)

zmbq
zmbq

Reputation: 39023

Well, the MSDN example has only one char * (or actually byte *). Remove the second one.

fixed(char* origionalPhrase = phrase, buffer = new char[25])
//                                   ^-- removed char*
{
   // ...
}

Upvotes: 6

helper
helper

Reputation: 41

fixed(char* origionalPhrase = phrase)
{
   fixed(char* buffer = new char[25])
   {
   ....
   ....
       now you can use origionalphrase and buffer inside.
   }
}

Upvotes: 4

Related Questions