|
-
September 3rd, 2010, 09:49 AM
#1
Constructor receiving struct as parameter
Does anyone know if I can send a struct as parameter into a constructor?
-
September 3rd, 2010, 10:42 AM
#2
Re: Constructor receiving struct as parameter
Like this?
Code:
value struct S
{
System::Int32 n;
};
ref class C
{
S myS;
public:
C(S s)
: myS(s)
{
}
};
-
September 3rd, 2010, 11:25 AM
#3
Re: Constructor receiving struct as parameter
It didn´t work for me.
-
September 3rd, 2010, 11:43 AM
#4
Re: Constructor receiving struct as parameter
Did it not compile???
What was the error?
-
September 3rd, 2010, 12:00 PM
#5
Re: Constructor receiving struct as parameter
error C2664: cannot convert parameter from ':Form1::S ^' to 'Form2::S ^'
Of course the struct name has been replaced, but it was declared into the two classes.
Last edited by MegaCode535; September 3rd, 2010 at 12:17 PM.
-
September 3rd, 2010, 12:17 PM
#6
Re: Constructor receiving struct as parameter
What did you compile? Neither ^ nor 'Teste' apears anywhere in my code. Have you tried compiling my code on its own?
-
September 3rd, 2010, 12:39 PM
#7
Re: Constructor receiving struct as parameter
My code compiles as it is. Why not try that first? The ^ should not be in there.
 Originally Posted by MegaCode535
error C2664: cannot convert parameter from ':Form1::S ^' to 'Form2::S ^'
Of course the struct name has been replaced, but it was declared into the two classes.
If you declared S inside Form1 and Form2 then Form1 and Form2 are two different types.
Last edited by Zaccheus; September 3rd, 2010 at 12:43 PM.
-
September 3rd, 2010, 12:53 PM
#8
Re: Constructor receiving struct as parameter
Yes, but the structs are the same. This doesn´t work even with the cast "Form1::S^"
-
September 3rd, 2010, 03:51 PM
#9
Re: Constructor receiving struct as parameter
No, they are two separate types. Also stop using ^ it is wrong.
Does my code compile on your compiler or not?
-
September 3rd, 2010, 07:07 PM
#10
Re: Constructor receiving struct as parameter
-
September 4th, 2010, 05:38 AM
#11
Re: Constructor receiving struct as parameter
What is the error message when you compile my code?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|