我對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