Newbie Convert int to int * ???

G

Guest

I have a sub:

void cdff ( int *m, double *p) {blah; blah;}

Later, I call it:

private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {

int m = 1;
double p = 2.3;
cdff (m, p);
blah; blah;
}

I get the error C2664 : cannot convert parameter 1 from 'int' to 'int *'

What is happening and how can I get the values 1 and 2.3 in a form that is
compatible with the function?
 
C

Carl Daniel [VC++ MVP]

mark said:
I have a sub:

void cdff ( int *m, double *p) {blah; blah;}

Fine, your function expects a pointer to int and a pointer to double -
presumably so that it can modify the variables passed to it.
Later, I call it:

private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {

int m = 1;
double p = 2.3;
cdff (m, p);

Here, you're passing an int and a double, which isn't what the function
expected.

change it to

cdff(&m,&p);
blah; blah;
}

I get the error C2664 : cannot convert parameter 1 from 'int' to 'int *'

What is happening and how can I get the values 1 and 2.3 in a form that is
compatible with the function?

You need to brush up on (or learn for the first time) basic principles of
values and pointers in C (or C++). I'd suggest Googling for "Thinking in
C++". It's an online e-book that's free and will answer this and many other
questions.

-cd
 
G

Guest

Thank you.
Your & worked!

The fact is, (dare I say it) I code in VB.NET. We don't worry about this
stuff.
I was forced back into the C++ world by a set of valuable functions (in C++)
that I want to translate into VB. (I needed to see data flow patterns in the
original implementations to be certain I was properly recoding.)

Long ago I coded in Borland C++., and yes I have forgoton so much. But I
don't miss it. Not having to count out every meter, I can now write an epic
poem.

But all that pomp and circumstance associated with C has charm doesn't it?
Perhaps I re-translate back into C sharp when I'm done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top