visual-studio - "type ' int ' unexpected"在构造函数中,找不到为什么?

标签 visual-studio class constructor c++-cli managed-c++

我对 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;
}
}

这 3 个错误是在 cpp 文件中我想要实现构造函数的行上抛出的。

希望有人能指出我做错了什么。

谢谢!

最佳答案

您没有正确限定构造函数。您需要其中另一个 Entry:::

Entry::Entry(int Id, int Year, String ^ Title, EntryType Type)

关于visual-studio - "type ' int ' unexpected"在构造函数中,找不到为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10882406/

相关文章:

c# - Entity Framework .edmx.sql 文件如何在已部署的应用程序中生成数据库?

java - 没有获得扩展类中变量的正确值

java - 不理解定义构造函数的 Java 语法

c++ - 如何将二进制字符串转换为base64编码的数据

spring - 如何将@Autowired 构造函数参数分别设置为 "required=false"

Java - 子类调用 super 构造函数,它调用子类方法而不是它自己的方法

.net - 远程调试.NET代码Visual Studio 2010

.net - 在 Visual Studio 2012 中生成 XML 序列化程序集不起作用

entity-framework - 如何在 Entity Framework 中添加外键关系?

php - 如何对php类进行分组?