help with my code  
Author Message
Flame Thrower





PostPosted: Visual C++ Language, help with my code Top

I am trying to build a clr app with a database (rpgcore.h) consisting of integers and string^s, as well as a few functions.

the auto-generated form1 is currently empty except for

#incude rpgcore.h

because i want to complete the database before actually displaying anything to the window. So, all my problems are in the rpgcore database. The database isnt complete but if these errors are fixed i should be able to complete it.

here is the rpgcore.h

//rpgcore.h

//contains the core rpg functions

/* start the database*/

namespace chara

{

namespace hero1

{

System::String^ name;

int hpmax[100];

int mpmax[100];

int rawatk[100];

int rawdef[100];

int level;

name = "Jacques";

level = 1;

}

}


Visual C++4  

 
 
Jonathan Caves - MSFT





PostPosted: Visual C++ Language, help with my code Top

I'll start with the first error: in C++/CLI you cannot, as the error message states, have a global variable whose type is a CLR type (in this case a reference type). Should hero1 be a class instead of a namespace

 
 
Flame Thrower





PostPosted: Visual C++ Language, help with my code Top

Sorry, i cant understand your post.

it may be because i never went to university or college (im not even old enough) and that there is no good CLR reference on the internet. You could say i dont know what i am doing but doing it is the only way to learn.

Could you explain how putting it in a class would help or if there is a way to convert a std::string to a system::string^ I would prefer the latter.


 
 
nobugz





PostPosted: Visual C++ Language, help with my code Top

A System::String^ can't be a global variable, as it is in your declaration, because it is a chicken-and-egg problem. C++ promises that constructors on global variables are called first but System::String^ requires the CLR to do the initialization. Which get loaded later.

The other errors you're getting is because you're executing code (name = "Jacques", level = 1) outside of a function body. The error messages are confusing because the compiler is trying to parse "name" but can't find a type declaration.

Sit back for a moment and ask yourself if writing .NET code in C++ is the right way to go. C++/CLI was invented to allow experienced C++ programmers to port their code from C++ to .NET. If you're starting from (almost) scratch, it is probably a much better idea to adopt C#. Or VB.NET, my favorite because I'm a C++ programmer and can't deal with the quirks of the C# syntax.

Good luck.



 
 
Nishant Sivakumar





PostPosted: Visual C++ Language, help with my code Top

To add to what others have said, just because it's a /clr app does not mean you need to use System::String. You can use a TCHAR array or an std::string just as well.