我对C#有一些经验,但C++语法和程序构造会造成一些问题。 我使用Visual C++ 2008首先为什么会出现这种错误?:C++没有适当的默认构造函数
1> ...... \ Form1.h(104):错误C2512: 'Cargame ::汽车':无适当的默认构造函数可用
其次,为什么不可能这条线? // System :: Drawing :: Color color;
错误C3265:不能声明在非托管 '汽车' 有管理的 '颜色'
Form1.h包含:Car.h的
namespace Cargame {
using namespaces bla bla bla
class Car;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
Car* car;
protected:
~Form1()
{
if (components)
{ delete components; }
}
SOME MORE AUTOMATICALLY GENERATED CODE
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
panel1->BackColor = System::Drawing::Color::Green;
car = new Car();
//car->draw();
}
};
}
内容:
class Car
{
private:
int speed;
//System::Drawing::Color color;
public:
Car();
};
Car.cpp的内容
#include "stdafx.h"
#include "Car.h"
#include "Form1.h"
#include <math.h>
//extern TForm1 *Form1;
Car::Car()
{
speed = 0;
}
void Car::draw()
{
//implementation
}
这不是C++,对不起。 ('public ref class'...不,绝对不是C++)。你的意思是C++/CLI或其他一些变体? – Arafangion 2012-03-12 00:26:33
我刚刚参加了新建项目中的Windows窗体应用程序...... 我有0经验C++ – 2012-03-12 00:29:49
在哪个版本的Visual Studio中? – Arafangion 2012-03-12 00:32:40