473,765 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<typena me Tref class ManagedImageMod ifier
{
public:
...
...

bool ChangeImage(Bit map^ 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 4221
Pixel.to.life wrote:
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<typena me Tref class ManagedImageMod ifier
{
public:
...
...

bool ChangeImage(Bit map^ 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????
I think first important step in the troubleshooting is
to decide on whether you are coding C++ or C# !

Arne
Jun 27 '08 #2
On Apr 21, 6:01*am, Arne Vajhøj <a...@vajhoej.d kwrote:
Pixel.to.life wrote:
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<typena me Tref class ManagedImageMod ifier
{
* *public:
* * * *...
* * * *...
* * * *bool ChangeImage(Bit map^ 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????

I think first important step in the troubleshooting is
to decide on whether you are coding C++ or C# !

Arne- Hide quoted text -

- Show quoted text -
It is managed C++.
I already got a solution on the VC group, doesnt quite work. That
solution recommended using a '%' qualifier instead of
a 'ref' keyword to pass by reference. It builds fine, but still same
issue: what is passed to the method is a different reference from what
is intended.

Since the problem spans a bit of both C++/CLI, I posted it here too.

Thanks anyways.
Jun 27 '08 #3
On Mon, 21 Apr 2008 09:14:53 -0700, Pixel.to.life
<pi***********@ gmail.comwrote:
It is managed C++.
Then you're posting to the wrong newsgroup. It does seem as though you
want to pass by reference. And if you were writing C# code, the "ref"
keyword would be useful for that.

But you're not. In C++ you can use the '&' character (not '%' AFAIK) and
it should work. If it doesn't, then you'll need to post your question to
a newsgroup specific to C++, not a newsgroup specific to C#.

Pete
Jun 27 '08 #4
Peter Duniho wrote:
On Mon, 21 Apr 2008 09:14:53 -0700, Pixel.to.life
<pi***********@ gmail.comwrote:
>It is managed C++.

Then you're posting to the wrong newsgroup. It does seem as though
you want to pass by reference. And if you were writing C# code, the
"ref" keyword would be useful for that.

But you're not. In C++ you can use the '&' character (not '%' AFAIK)
and it should work. If it doesn't, then you'll need to post your
question to a newsgroup specific to C++, not a newsgroup specific to
C#.
& is standard C++ for a reference.
Standard C++ pointers and references don't play well with a compacting
garbage collector such as .NET has, because objects move around in memory.
So C++/CLI adds a tracking handle (^) and tracking reference (%) which are
GC-aware. The tracking reference is how you define a parameter which C#
sees as "ref" or "out".
>
Pete

Jun 27 '08 #5
On Mon, 21 Apr 2008 10:39:17 -0700, Ben Voigt [C++ MVP]
<rb*@nospam.nos pamwrote:
[...]
So C++/CLI adds a tracking handle (^) and tracking reference (%) which
are
GC-aware. The tracking reference is how you define a parameter which C#
sees as "ref" or "out".
Ah, okay.

Well, there's a good example of why this question doesn't belong in this
newsgroup. :)

To the OP: if you can't get % to work for you, you need to post your
question in a managed C++ newsgroup. It has nothing to do with C#. I
recommend when you do so, that you include a concise-but-complete code
sample that reliably demonstrates the problem.

Pete
Jun 27 '08 #6
Pixel.to.life wrote:
It is managed C++.
I already got a solution on the VC group, doesnt quite work. That
solution recommended using a '%' qualifier instead of
a 'ref' keyword to pass by reference. It builds fine, but still same
issue: what is passed to the method is a different reference from what
is intended.

Since the problem spans a bit of both C++/CLI, I posted it here too.
This group has nothing to with C++ or C++/CLI.

It is easy to show that % is working.

Simple example:

#using <mscorlib.dll >

using namespace System;

void f1(String^ s)
{
s = "f1";
}

void f2(String^ %s)
{
s = "f2";
}

int main(array<Stri ng^^args)
{
String^ s = "ABC";
Console::WriteL ine(s);
f1(s);
Console::WriteL ine(s);
f2(s);
Console::WriteL ine(s);
return 0;
}
Arne
Jun 27 '08 #7

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

Similar topics

3
4584
by: Andrew Luke | last post by:
Hi all you C++ guru's! I'm 'very, very' new to C++ and I'm having a little trouble configuring my VS environment I think - when I try and compile some sample code I'm getting the following errors, any help would be 'greatly' appreciated! :) Thanks heaps! --------------------Configuration: CppRichTextItem - Win32 Debug-------------------- Compiling...
1
6479
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 under Visual Studio .NET 2003 in a Win32 Console Project // VectorInsert.cpp : Defines the entry point for the console application / #include "stdafx.h #include "VectorInsert.h #ifdef _DEBU
0
1947
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); System::Void HandlerLineReceived(TCP_Client* sender, String* Data)
25
3999
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 and 09 because they are not octal. Is there any way to coerce the input variable to decimal despite it having a leading zero .
6
2982
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 outside too. Something like this:
8
2451
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 want to know what does the standard say about this situation. here is the code just to demonstrate the error.
10
3069
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 error C2086: 'char &junkChar' : redefinition see declaration of 'junkChar'
15
5695
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 studio\vc98\include\winuser.h(39) : error C2061: syntax error : identifier 'HDWP'
6
38062
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
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.