Arrays and enums in an extended control
-
Hi, I'm completely new to C++ as a whole, so there might be a simple answer to my question, so here goes. I'm trying to write a program that will have the screen broken up into zones, or areas, each with a Point (location) a Size, an Image, and an array of terrain types (an enum). Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this, I tried extending the PictureBox control, but this has given me even more headaches. Basically, I can't figure out how to declare/use an array in an extended control.
#pragma once
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace cli; //something I think MSDN said I had to donamespace MapEdit
{
//better than a "magic number". there can only be 3 different types of terrain per square
//used in the TerrainTypes array
const int MAX_TERRAIN = 3;public ref class Zone : public System::Windows::Forms::PictureBox { public: enum Terrain //says I can't mix types { Plain, Hill, Wood, Marsh, Stream, River, ShoreLine, Impassable }; array<byte^> ^TerrainTypes; //this doesn't work int TerrainTypes\[3\]; //neither does this.
... All of my errors (except the parts where I try to use these faulty enum/ array) come from this block. Frankly, I'm at a loss as to how to fix this. Also, if someone could tell me how to include a Bitmap in an unmanged class, that would be nice too. Thanks, Christian
-
Hi, I'm completely new to C++ as a whole, so there might be a simple answer to my question, so here goes. I'm trying to write a program that will have the screen broken up into zones, or areas, each with a Point (location) a Size, an Image, and an array of terrain types (an enum). Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this, I tried extending the PictureBox control, but this has given me even more headaches. Basically, I can't figure out how to declare/use an array in an extended control.
#pragma once
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace cli; //something I think MSDN said I had to donamespace MapEdit
{
//better than a "magic number". there can only be 3 different types of terrain per square
//used in the TerrainTypes array
const int MAX_TERRAIN = 3;public ref class Zone : public System::Windows::Forms::PictureBox { public: enum Terrain //says I can't mix types { Plain, Hill, Wood, Marsh, Stream, River, ShoreLine, Impassable }; array<byte^> ^TerrainTypes; //this doesn't work int TerrainTypes\[3\]; //neither does this.
... All of my errors (except the parts where I try to use these faulty enum/ array) come from this block. Frankly, I'm at a loss as to how to fix this. Also, if someone could tell me how to include a Bitmap in an unmanged class, that would be nice too. Thanks, Christian
poppabaggins wrote:
Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this
Rather than work around by making something up yourself I would strongly suggest that you learn C++/CLI. There are excellent tutorial articles on CLI here at CodeProject. Look under the "Chapters" in the site menu. Of course I would also strongly recommend you learn C++ first and then learn C++/CLI. I mean CLI is an extension so it seems rather obvious that one learns the root before the extension, but what do I know right?
led mike
-
Hi, I'm completely new to C++ as a whole, so there might be a simple answer to my question, so here goes. I'm trying to write a program that will have the screen broken up into zones, or areas, each with a Point (location) a Size, an Image, and an array of terrain types (an enum). Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this, I tried extending the PictureBox control, but this has given me even more headaches. Basically, I can't figure out how to declare/use an array in an extended control.
#pragma once
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace cli; //something I think MSDN said I had to donamespace MapEdit
{
//better than a "magic number". there can only be 3 different types of terrain per square
//used in the TerrainTypes array
const int MAX_TERRAIN = 3;public ref class Zone : public System::Windows::Forms::PictureBox { public: enum Terrain //says I can't mix types { Plain, Hill, Wood, Marsh, Stream, River, ShoreLine, Impassable }; array<byte^> ^TerrainTypes; //this doesn't work int TerrainTypes\[3\]; //neither does this.
... All of my errors (except the parts where I try to use these faulty enum/ array) come from this block. Frankly, I'm at a loss as to how to fix this. Also, if someone could tell me how to include a Bitmap in an unmanged class, that would be nice too. Thanks, Christian
Are you trying to make an array of enums? If so, why did you try to create a byte (whatever that is) array and an int array? First, you can't embed a native enumeration in a ref class. Second, once you have a managed enum class, you can create an array that stores the enum type...
enum class Terrain { Plain, Hill, Wood, Marsh, Stream, River, ShoreLine, Impassable }; array<Terrain> ^TerrainTypes;
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
poppabaggins wrote:
Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this
Rather than work around by making something up yourself I would strongly suggest that you learn C++/CLI. There are excellent tutorial articles on CLI here at CodeProject. Look under the "Chapters" in the site menu. Of course I would also strongly recommend you learn C++ first and then learn C++/CLI. I mean CLI is an extension so it seems rather obvious that one learns the root before the extension, but what do I know right?
led mike
led mike wrote:
it seems rather obvious that one learns the root before the extension
:laugh: Good one. You hang out on the C# board....it's pretty obvious there's a whole new generation of "programmers" that have completely bypassed the fundamentals. :beer:
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
led mike wrote:
it seems rather obvious that one learns the root before the extension
:laugh: Good one. You hang out on the C# board....it's pretty obvious there's a whole new generation of "programmers" that have completely bypassed the fundamentals. :beer:
Mark Salsbery Microsoft MVP - Visual C++ :java:
Mark Salsbery wrote:
it's pretty obvious there's a whole new generation of "programmers" that have completely bypassed the fundamentals.
they also seem to mostly bypass thinking. ;) It's likely a symptom of Drag and Drop development. Vee Bee Stupid :jig:
led mike
-
Are you trying to make an array of enums? If so, why did you try to create a byte (whatever that is) array and an int array? First, you can't embed a native enumeration in a ref class. Second, once you have a managed enum class, you can create an array that stores the enum type...
enum class Terrain { Plain, Hill, Wood, Marsh, Stream, River, ShoreLine, Impassable }; array<Terrain> ^TerrainTypes;
Mark Salsbery Microsoft MVP - Visual C++ :java:
Thanks, I was trying to come up with some sort of sensible code from searching the internet, but nothing seemed to work for me. Basically, I'm working off of what little I know from C# and the small amount of information I can get from my professor after class. It obviously wasn't working well for me. This is part of a project for school, but my book has absolutely nothing on managed c++. I would take the time to learn C++/cli, but this project is due at the end of the semester, and I have so many other things I'm reading now for classes/personal study/entertainment. I'll get to it eventually, but I have a lot of other things I'm doing now.