473,406 Members | 2,816 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.

passing a struct with an array by reference

AM
I have a struct that has an array in it. I need to assign space to the
array in a function and pass the corresponding struct by reference to
another function so that it can store values into the array. When I
try it with the following code i get these errors
1. Use of possibly unassigned field 'micData'
2. The out parameter 'rem' must be assigned to before control leaves
the current method

Could someone point out how to do this and what I am doing wrong. Any
help is greatly appreciated.
---------CODE-----------

Class X{
public struct micDataReturn
{
public double[] micData;//data from the microphone
public double noiseValue;//noise in dB of the data
}

public X()
{

}
public void getData(out micDataReturn rem)
{
try{
rem.micData[0] = 0;
rem.micData[1] = 0;
rem.micData[2] = 0;
}
catch(Exception e)
{
}
}

static void main()
{
X myx = new X();
micDataReturn res = new micDataReturn();
res.micData = new double[10];
X.getData(out res)
}
}

-------------------

Thanks in advance.

May 3 '07 #1
1 1209
From: "AM"
>I have a struct that has an array in it. I need to assign space to the
array in a function and pass the corresponding struct by reference to
another function so that it can store values into the array. When I
try it with the following code i get these errors
1. Use of possibly unassigned field 'micData'
2. The out parameter 'rem' must be assigned to before control leaves
the current method

The error is because you declared getData's parameter to be an out param.

Please read http://msdn2.microsoft.com/en-us/lib...30(VS.80).aspx
for a discussion.

Also, next time, please try to cut and paste actual code--I had to fix a
bunch of typos to get the program to almost compile before figuring out the
problem.

May 5 '07 #2

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

Similar topics

15
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. ...
58
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...
1
by: Tobias | last post by:
Hi! I have a problem which is quite tricky. I need to pass a struct from .NET to a native Win32 DLL. But i just need to pass the pointer to a reference of that struct. With my first struct this...
9
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...
2
by: Steve Turner | last post by:
I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows: typedef struct tag_scanparm { short...
12
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
11
by: abhiM | last post by:
I have a struct that has an array in it. I need to assign space to the array in a function and pass the corresponding struct by reference to another function so that it can store values into the...
8
by: S. | last post by:
Hi all, Can someone please help me with this? I have the following struct: typedef struct { char *name; int age; } Student;
13
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper in C# for an SDK that has been supplied as a .LIB file and a .h header file. I have got most of the functions to work but am really struggling with the...
4
by: arnuld | last post by:
I am passing an array of struct to a function to print its value. First I am getting Segfaults and weired values. 2nd, is there any elegant way to do this ? /* Learning how to use an array...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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.