Click to See Complete Forum and Search --> : error C2440: '=' : cannot convert from 'System::String __gc *' to 'char [10]'


ZooBooBooZoo
December 4th, 2005, 11:29 AM
Hi all, I get the error in the title when trying to compile my Visual c++ project(Using VS2003)

this is the body:

#pragma once
typedef struct
{
char Title[100];
char Lyrics[100];
}DefLyrics;
DefLyrics LyricsDB;

[...]

private: System::Void btnAddLyricsToDB_Click(System::Object * sender, System::EventArgs * e)
{
LyricsDB.Title = _T(this->txtInsertLyricsTitle->Text);
this->txtLyrics->Text = _T(LyricsDB.Title);
}

};
}

Siddhartha
December 4th, 2005, 12:10 PM
[ redirected ]

Regards,
Siddhartha

cilu
December 4th, 2005, 01:05 PM
See this article http://support.microsoft.com/default.aspx?scid=kb;EN-US;311259.

But...

If you are using ManagedC++, why don't you use System::String?

using namespace System::Runtime::InteropServices;

[StructLayout( LayoutKind::Sequential, CharSet=CharSet::Ansi )]
__gc struct DefLyrics
{
System::String* Title;
System::String* Lyrics;
};

ZooBooBooZoo
December 4th, 2005, 01:21 PM
This is what I get:
error C3145: 'LyricsDB' : cannot declare a global or static managed type object or a __gc pointer

cilu
December 4th, 2005, 03:17 PM
The error message is self-explaining in my opinion. Make it a member of a class and you'll get rid of it.

darwen
December 6th, 2005, 01:28 AM
Generally speaking I've found keeping the same convention as C# with structs and classes (i.e. structs are value types, classes are reference types) is a good idea :


[StructLayout( LayoutKind::Sequential, CharSet=CharSet::Ansi )]
__value struct DefLyrics
{
System::String* Title;
System::String* Lyrics;
};


Darwen.