【发布时间】:2012-06-04 13:45:12
【问题描述】:
我对 C++ 和他的语法很陌生。我以前用 C# 编程过,但想试试 C++。
我在 Visual Studio 中创建了一个 ClassLibrary,并想向其中添加一些类。我知道这是托管 C++。
但我无法理解为什么我不断收到这些错误:
Error C2062: type 'int' unexpected
Error C2143: syntax error: messing ; before '{'
Error C2447: '{' : missing function header (old-style formal list?)
这是我的头文件:
// LibraryLib.h
#pragma once
#include <string>
using namespace System;
namespace LibraryLib {
public enum EntryType {Book, Newspaper};
public ref class Entry
{
public:
int id;
int year;
String ^ title;
EntryType type;
Entry(int Id, int Year, String ^ Title, EntryType Type);
};
}
这是我的 cpp 文件:
// This is the main DLL file.
#include "stdafx.h"
#include "LibraryLib.h"
namespace LibraryLib {
LibraryLib::Entry(int Id, int Year, String ^ Title, EntryType Type) // line of errors
{
id = Id;
year = Year;
title = Title;
type = Type;
}
}
在我想在cpp文件中实现构造函数的那一行抛出了3个错误。
我希望有人能指出我做错了什么。
谢谢!
【问题讨论】:
-
他的语法?我一直认为 C++ 是一个她。曾经的妖精,有着炽热的性情淬炼出的裸机速度的魅力,是凡人无法理解的。
标签: visual-studio class constructor c++-cli managed-c++