VisualStudio 2017:语法错误在'^'之前缺少':'

时间:2018-07-04 14:21:56

标签: winforms visual-studio-2017 c++-cli

我有以下内容:

FileReader.cpp

#include "FileReader.h"
#include "FileData.h"

using namespace System;
using namespace System::IO;


FileReader::FileReader(){}

System::Void FileReader::readFile(System::String^ fileName) {
    this->_fileName = fileName;
    Console::WriteLine("Opening: " + _fileName);

    try {
        StreamReader^ fileIn = File::OpenText(_fileName);

        System::String^ input;
        int count = 0;
        while ((count < 10 && (input = fileIn->ReadLine()) != nullptr)) {
            Console::WriteLine(input);
            count++;
        }

    }
    catch (FileNotFoundException^ e) {
        Console::WriteLine("FileNotFound");
    }
}

FileReader.h

#pragma once

ref class FileReader
{
public:
    FileReader();

    FileData^ fData = gcnew FileData(); // This is whats causing the errors.
    System::String^ _fileName;
    System::Void readFile(System::String^ fileName);
};

FileData.cpp

#include "FileData.h"

FileData::FileData(){}

System::Void FileData::Set_DataName(System::String^ dName)
{
    this->dataName= dName;
}

FileData.h

#pragma once
using namespace System;

ref class FileData
{
public:
    FileData();

    System::String^ dataName;
    System::Void Set_PlayerName(System::String^ dName);

};

我遇到的问题是,尝试在FileReader.h中创建FileData对象时,编译器会返回大量错误信息

Error   C2143   syntax error: missing ';' before '^'
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    
Error   C2238   unexpected token(s) preceding ';'
Error   C2143   syntax error: missing ';' before '^'
Error   C4430   missing type specifier - int assumed.
Error   C2238   unexpected token(s) preceding ';'
Error   C2143   syntax error: missing ';' before '^'    
Error   C4430   missing type specifier - int assumed. 
Error   C2238   unexpected token(s) preceding ';'

我知道我可能错过了一些简单的事情,但是我不知道自己做错了什么。有人能帮忙吗?

0 个答案:

没有答案