473,750 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing by ref?

I am calling a function with a reference parameter. Inside the function
(GetXMLRecord)
I am changing the input parameter. When the function returns, input
parameter is not reflecting the change. This would have worked in C++,
but not here

What I am doing wrong? Pls help.
ref class ImageFileData
{
public NameValueCollec tion^ m_pNameValueCol lection;
public:
ImageFileData()
{
m_pNameValueCol lection = gcnew NameValueCollec tion;
}
int GetXMLRecord( NameValueCollec tion^ data)
{
if(m_pNameValue Collection->Count)
{
data = m_pNameValueCol lection; ///VALUE set here to "data" does
not get

///here will not carried to caller
}
return 0;
}
}
public ref class Test : public System::Windows ::Forms::Form
{
ImageFileData^ m_pImageFileDat a;
}
void Test :: initControlsFro mXML( )
{
NameValueCollec tion^ objCustomData ;
m_pImageFileDat a->GetXMLRecord ( objCustomData); //////VALUE set
inside function does
//not hold good when the function returns
}

Feb 20 '06 #1
3 986

<as*******@gmai l.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
|I am calling a function with a reference parameter. Inside the function
| (GetXMLRecord)
| I am changing the input parameter. When the function returns, input
| parameter is not reflecting the change. This would have worked in C++,
| but not here
|
| What I am doing wrong? Pls help.
|
|
| ref class ImageFileData
| {
| public NameValueCollec tion^ m_pNameValueCol lection;
| public:
| ImageFileData()
| {
| m_pNameValueCol lection = gcnew NameValueCollec tion;
| }
| int GetXMLRecord( NameValueCollec tion^ data)
| {
| if(m_pNameValue Collection->Count)
| {
| data = m_pNameValueCol lection; ///VALUE set here to "data" does
| not get
|
| ///here will not carried to caller
| }
| return 0;
| }
| }
|
|
| public ref class Test : public System::Windows ::Forms::Form
| {
| ImageFileData^ m_pImageFileDat a;
| }
| void Test :: initControlsFro mXML( )
| {
| NameValueCollec tion^ objCustomData ;
| m_pImageFileDat a->GetXMLRecord ( objCustomData); //////VALUE set
| inside function does
| //not hold good when the function returns
| }
|

GetXMLRecord(Na meValueCollecti on^% data)
or
GetXMLRecord([Runtime::Intero pServices::Out]NameValueCollec tion^% data)
Willy.
Feb 20 '06 #2
> GetXMLRecord(Na meValueCollecti on^% data)

or you can simply use:
GetXMLRecord(Na meValueCollecti on^%#&@* data)

:-)

Just a little humor about how out of hand the syntax is getting. :-)

--
Greg McPherran
www.McPherran.com
Feb 22 '06 #3
Greg wrote:
GetXMLRecord( NameValueCollec tion^% data)

or you can simply use:
GetXMLRecord(Na meValueCollecti on^%#&@* data)

:-)

Just a little humor about how out of hand the syntax is getting. :-)


Why do you say that? In native C++ it was *&. Now it's ^%. You have to
be able to differenciate between native pointers and managed handles.
Not like in the old MC++ hell, when you had absolutely no idea what the
* was meaning.

Would it be better to write

GetXMLRecord(Na meValueCollecti on __gc* __gc& data)

???

Tom
Feb 22 '06 #4

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

Similar topics

15
4681
by: Dave | last post by:
I'm currently working on a small project (admitedly for my CS class) that compares the time difference between passing by value and passing by reference. I'm passing an array of 50000 int's. However, since in C++ an array is passed by reference by default I need to embed the array into a struct in order to pass it by value. The problem is that I get a segmentation error when doing so. I'm using the Dev-c++ compiler. Any ideas? ...
58
10170
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
9
2298
by: Just Me | last post by:
PARAFORMAT2 is a structure that SendMessage will return stuff in. Is the "ref" correct or since only a pointer is being passed should it be by value? Suppose I was passing data rather then receiving it, would that change the answer to the above?
8
2117
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects, each requiring a call to that method to fulfill their purpose. There could be 200, there could be more than 1000. That is a lot of references passed around. It feels heavy. Let us say i changed the signature of the interface method to:
22
25597
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to compile. <WebMethod()> _ Public Function VerifySku(ByVal skus As XmlDataDocument) As DataSet Test program : Dim cartSet As DataSet cartSet = ws.VerifySku(cartSet)
6
5996
by: MSDNAndi | last post by:
Hi, I get the following warning: "Possibly incorrect assignment to local 'oLockObject' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the original value of the local." My code is: using System; using System.Collections.Generic;
12
2683
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
12
5400
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
7
3305
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the object is a reference type? my code is not proving that. I have a web project i created from a web service that is my object: public class ExcelService : SoapHttpClientProtocol {
4
2812
by: Deckarep | last post by:
Hello fellow C# programmers, This question is more about general practice and convention so here goes: I got into a discussion with a co-worker who insisted that as a general practice all objects should be passed by reference using the ref keyword generally speaking because as the writer of code you are conveying your intentions that an Object should/can be modified by your function.
0
8999
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
9575
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...
1
9338
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
9256
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
8260
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...
1
6803
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3322
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
2
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.