By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

Please help with a small question

P: n/a

Hi ,

I'm a newbe to programming and have a small question:

I made a small program with a class. in the class's header file I have
: double *ptr_output;

Void main()
{
double result[4];

class class_name(4); //constructor

class.method(result);
}

class.method(double *output)
{
memcpy(output,ptr_output,4);
}

class constructor
{
ptr_output = new double[length];
}
Why doesn't this work ? I want the method to peform some work on the
data and then return it to the result array.

Please help

--
Gena
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Jan 10 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Gena wrote:
Hi ,

I'm a newbe to programming and have a small question:

I made a small program with a class. in the class's header file I have
: double *ptr_output;

Void main()
{
double result[4];

class class_name(4); //constructor

class.method(result);
}

class.method(double *output)
{
memcpy(output,ptr_output,4);


Apart from numerous syntax errors, the most obvious problem is the line
above. It should be:

memcpy(output,ptr_output,4 * sizeof ptr_output[0]);

memcpy takes a byte count, but doubles are bigger than 1 byte, so you
need to multiply up by sizeof(double). I've used sizeof ptr_output[0] in
case you ever change the type of ptr_output (e.g. to long double or float).

Why didn't you copy-and-paste your real code? Surely that's quicker than
typing it out again?

Tom
Jan 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.