473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

error C2061: syntax error : identifier 'ref'

So I have this perfectly fine and running app, that uses managed C++
forms.

Problem#1:
[1] I pass a Bitmap reference to a class, hoping to modify it in one
of the class's methods, so it reflects outside too. Something like
this:
// In a form's scope
Bitmap ^m_Bitmap;
// A separate class
template<typename Tref class ManagedImageModifier
{
public:
...
...
bool ChangeImage(Bitmap^ iImage)
{
// change iImage here
....
return true;
};

};
This builds fine. The problem is that iImage has a different address
in memory than the reference I pass in. Obviously this means any
change to iImage isnt reflected outside. This came as a surprise
initially to me as I am new to managed programming.

Problem#2:
Anyways, I chose to classify this parameter as a reference variable,
by using 'ref' keyword. Something like this
bool ChangeImage(ref Bitmap^ iImage)
{
// change iImage here
....
return true;
};
And now I get this compile error:
error C2061: syntax error : identifier 'ref'
Note that the same keyword when used to classify the class
ImageModifier wasnt giving me errors.
Any clues on whats going on here????
Thanks a lot!
-P.
Jun 27 '08 #1
6 2965
Problem#2:
Anyways, I chose to classify this parameter as a reference variable,
by using 'ref' keyword. Something like this
This is the right thing to do, but the wrong syntax.
>

bool ChangeImage(ref Bitmap^ iImage)
{
// change iImage here
....
return true;
};
And now I get this compile error:
error C2061: syntax error : identifier 'ref'
Note that the same keyword when used to classify the class
ImageModifier wasnt giving me errors.
Any clues on whats going on here????
C# uses the ref keyword for this. C++ already had language syntax for
reference parameters, so C++/CLI adapted that instead of following C#.

Try

bool ChangeImage(Bitmap^% iImage) { ... }

>

Thanks a lot!
-P.

Jun 27 '08 #2
Thanks Ben.

I tried that, now it compiled file. But the memory address of the
original image and the one I receive inside ChangeImage(..) is still
different. Is there a rul for calling this method too?

I call it like this:

// In a form's scope
Bitmap ^m_Bitmap;
ManagedImageModifier<MyModifiermodifier;

bool result = modifier.ChangeImage(m_Bitmap);


On Apr 21, 6:37*am, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
Problem#2:
Anyways, I chose to classify this parameter as a reference variable,
by using 'ref' keyword. Something like this

This is the right thing to do, but the wrong syntax.


bool ChangeImage(ref Bitmap^ iImage)
* * * {
* * * * *// change iImage here
* * * * *....
* * * * *return true;
* * * };
And now I get this compile error:
error C2061: syntax error : identifier 'ref'
Note that the same keyword when used to classify the class
ImageModifier wasnt giving me errors.
Any clues on whats going on here????

C# uses the ref keyword for this. *C++ already had language syntax for
reference parameters, so C++/CLI adapted that instead of following C#.

Try

bool ChangeImage(Bitmap^% iImage) { ... }


Thanks a lot!
-P.- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Jun 27 '08 #3
Pixel.to.life wrote:
Thanks Ben.

I tried that, now it compiled file. But the memory address of the
original image and the one I receive inside ChangeImage(..) is still
different. Is there a rul for calling this method too?
It's a garbage collected object, so it can move around in memory. That's
why ^ and % ("tracking" pointer and reference) instead of * and &.

Can you verify whether the function was able to change the caller's copy of
the variable?
>
I call it like this:

// In a form's scope
Bitmap ^m_Bitmap;
ManagedImageModifier<MyModifiermodifier;

bool result = modifier.ChangeImage(m_Bitmap);


On Apr 21, 6:37 am, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
>>Problem#2:
Anyways, I chose to classify this parameter as a reference variable,
by using 'ref' keyword. Something like this

This is the right thing to do, but the wrong syntax.


>>bool ChangeImage(ref Bitmap^ iImage)
{
// change iImage here
....
return true;
};
>>And now I get this compile error:
>>error C2061: syntax error : identifier 'ref'
>>Note that the same keyword when used to classify the class
ImageModifier wasnt giving me errors.
>>Any clues on whats going on here????

C# uses the ref keyword for this. C++ already had language syntax for
reference parameters, so C++/CLI adapted that instead of following
C#.

Try

bool ChangeImage(Bitmap^% iImage) { ... }


>>Thanks a lot!
>>-P.- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Jun 27 '08 #4
Pixel.to.life wrote:
Thanks Ben.

I tried that, now it compiled file. But the memory address of the
original image and the one I receive inside ChangeImage(..) is still
different. Is there a rul for calling this method too?

I call it like this:

// In a form's scope
Bitmap ^m_Bitmap;
ManagedImageModifier<MyModifiermodifier;

bool result = modifier.ChangeImage(m_Bitmap);
Does it still misbehave when simplified?

Try this:

Bitmap ^m_Bitmap;

m_Bitmap = gcnew Bitmap(64, 64);
::System::Diagnostics::Trace::WriteLine("m_Bitmap " + ((m_Bitmap ==
nullptr)? "is": "is not") + " NULL");
ChangeImage(m_Bitmap);
::System::Diagnostics::Trace::WriteLine("m_Bitmap " + ((m_Bitmap ==
nullptr)? "is": "is not") + " NULL");

bool ChangeImage(Bitmap^% bmp) { bmp = nullptr; return true; }

Then move ChangeImage into your template class as a static method, call it
there, test again.
Then make ChangeImage an instance method, test again.
Then start adding the ChangeImage logic.

I suspect that ChangeImage didn't reach the line which reassigned the
parameter to a new value. It is declared with a return value but you aren't
checking it.
Jun 27 '08 #5
On Apr 21, 10:43*am, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
Pixel.to.life wrote:
Thanks Ben.
I tried that, now it compiled file. But the memory address of the
original image and the one I receive inside ChangeImage(..) is still
different. Is there a rul for calling this method too?
I call it like this:
// In a form's scope
Bitmap *^m_Bitmap;
ManagedImageModifier<MyModifiermodifier;
bool result = modifier.ChangeImage(m_Bitmap);

Does it still misbehave when simplified?

Try this:

Bitmap ^m_Bitmap;

m_Bitmap = gcnew Bitmap(64, 64);
::System::Diagnostics::Trace::WriteLine("m_Bitmap " + ((m_Bitmap ==
nullptr)? "is": "is not") + " NULL");
ChangeImage(m_Bitmap);
::System::Diagnostics::Trace::WriteLine("m_Bitmap " + ((m_Bitmap ==
nullptr)? "is": "is not") + " NULL");

bool ChangeImage(Bitmap^% bmp) { bmp = nullptr; return true; }

Then move ChangeImage into your template class as a static method, call it
there, test again.
Then make ChangeImage an instance method, test again.
Then start adding the ChangeImage logic.

I suspect that ChangeImage didn't reach the line which reassigned the
parameter to a new value. *It is declared with a return value but you aren't
checking it.- Hide quoted text -

- Show quoted text -
Ben,

That worked like a charm.

Thanks a ton. I was stuck on this for almost a day!!!

Hope I can be of some use to you too someday:-)
Jun 27 '08 #6
Ben,
>
That worked like a charm.

Thanks a ton. I was stuck on this for almost a day!!!

Hope I can be of some use to you too someday:-)
You're welcome.
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Avery Fong | last post by:
The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug This program is developed...
0
by: MWK | last post by:
Hi All, I don't understand why I get "error c2061: syntax error : identifier" in VS2003. I thought it's fixed in .Net 2003: __hook(&TCP_Client::LineReceived, client, HandlerLineReceived); ...
25
by: notahipee | last post by:
I have been trying to cin an number from 0 to 9 with a leading 0. For example 00 or 07. I was using a switch case. switch (int) { case 01: break; case 02: break;..... My problem arises at 08...
6
by: Pixel.to.life | last post by:
So I have this perfectly fine and running app, that uses managed C++ forms. Problem#1: I pass a Bitmap reference to a class, hoping to modify it in one of the class's methods, so it reflects...
8
by: =?GB2312?B?yum09MXt?= | last post by:
today I forgot to include some header,then I found the error message by the compiler is quite strange. so I want to know exactly the inner details of the compiler impletation,if possible. and I...
10
by: charmeda103 | last post by:
My program keeps getting me and error and i dont why here is the error message error C2061: syntax error: identifier 'infile' error C2660: 'ReadDate' : function does not take 6 arguments...
15
by: madhu.ab | last post by:
Hi All, I am getting the following errors when i am including header file winuser.h I dont know whats happening. How will an error occur in winuser.h?? Please help. \microsoft visual...
6
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.