error C4368: cannot define 'p' as a member of managed 'snake::Form1': mixed

who can help me?
error C4368: cannot define 'p' as a member of managed 'snake::Form1': mixed types are not supported

//Form1.h

#pragma once
#include "point.h"
#include "stdafx.h"
#include <iostream>

using namespace std;

char _x = 'r';



namespace snake {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{

static int x = 100;
static int y = 56;

point* p;

private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::PictureBox^ point;


public:

Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
p = new point();
}

bool istuch()
{
if((x + 12 >= p->x && x <= p->x) && (y + 12 >= p->y && y <= p->y)) return true;
//if((x >= p.x && x <= p.x + 12) && (y >= p.y && y <= p.y + 12)) return true;
//if((x + 12 >= p.x && x <= p.x) && (y >= p.y && y <= p.y + 12)) return true;
//if((y + 12 >= p.y && y <= p.y) && (x >= p.x && x <= p.x + 12)) return true;
return false;
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}

private: System::Windows::Forms::Timer^ timer1;
private: System::ComponentModel::IContainer^ components;
protected:


private:
/// <summary>
/// Required designer variable.
/// </summary>


#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->point = (gcnew System::Windows::Forms::PictureBox());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->point))->BeginInit();
this->SuspendLayout();
//
// timer1
//
this->timer1->Enabled = true;
this->timer1->Interval = 10;
this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
//
// pictureBox1
//
this->pictureBox1->BackColor = System::Drawing::SystemColors::ActiveCaptionText;
this->pictureBox1->Location = System::Drawing::Point(66, 51);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(12, 12);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// point
//
this->point->BackColor = System::Drawing::SystemColors::ActiveCaption;
this->point->Location = System::Drawing::Point(200, 51);
this->point->Name = L"point";
this->point->Size = System::Drawing::Size(12, 12);
this->point->TabIndex = 1;
this->point->TabStop = false;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(509, 349);
this->Controls->Add(this->point);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyDown);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->point))->EndInit();
this->ResumeLayout(false);

}
#pragma endregion
private: System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if(e->KeyCode == Keys::W)
{
if(_x != 'd') _x = 'u';
//pictureBox1->Load("images/u_head.png");
}

if(e->KeyCode == Keys::S)
{
if(_x != 'u') _x = 'd';
//pictureBox1->Load("images/d_head.png");
}

if(e->KeyCode == Keys::A)
{
if(_x != 'r') _x = 'l';
//pictureBox1->Load("images/l_head.png");
}

if(e->KeyCode == Keys::D)
{
if(_x != 'l') _x = 'r';
//pictureBox1->Load("images/r_head.png");
}

if(e->KeyCode == Keys::Q)
{
point->Visible = true;
}
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
if( _x == 'r')
{
x += 1;
}

if( _x == 'd')
{
y += 1;
}

if( _x == 'u')
{
y -= 1;
}

if( _x == 'l')
{
x -= 1;
}

pictureBox1->Location = System::Drawing::Point(x, y);

if(istuch())
{
point->Visible = false;
}
}
};
}

//point.h

#pragma once
#ifndef POINT_H
#define POINT_H

namespace snake
{
public class point
{
public:
int x;
int y;
point()
{
x = 300;
y = 56;
}
};
}

#endif
Last edited on
closed account (z05DSL3A)
Gor wrote:
who can help me?
error C4368: cannot define 'p' as a member of managed 'snake::Form1': mixed types are not supported

You are trying to mix native C++ with managed C++/CLI, this is not allowed.

edit:
I can see that you are at least you are trying to use the native type via a pointer...
Last edited on
But how can i do like this, i want define a class 'point' and than define 'point p' in public ref class Form1?
And when i`m tring like this



point* p;

public:

Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
p = new point();
}

there are errors like this.

1>_snake.obj : error LNK2020: unresolved token (0A000019) "private: static char _snake::_direction" (?_direction@_snake@@$$Q0DA)
1>_snake.obj : error LNK2020: unresolved token (0A00001A) "private: static int _snake::_lenght" (?_lenght@_snake@@$$Q0HA)
1>_snake.obj : error LNK2001: unresolved external symbol "private: static char _snake::_direction" (?_direction@_snake@@$$Q0DA)
1>_snake.obj : error LNK2001: unresolved external symbol "private: static int _snake::_lenght" (?_lenght@_snake@@$$Q0HA)
1>C:\Users\jergo\documents\visual studio 2010\Projects\snake\Debug\snake.exe : fatal error LNK1120: 4 unresolved externals
closed account (z05DSL3A)
Sorry, been a bit busy with work.

I have put your (original) code into a project and tried building it.
Didn't get the same error as you reported and it was just a matter of changing p = new point(); to p = new snake::point(); to get it to build.

if you are having error C4368, you may have some project settings wrong...let me just check something...

Edit:
No, I can't reproduce your error.
Last edited on
Topic archived. No new replies allowed.