我的 Array<byte>^ 函数在以前的项目中有效,但在最近的项目中不起作用



我最近一直在研究DirectX,我有一个Array<byte>^函数来读取程序中的着色器。这个函数在我3天前制作的一个程序中工作,但后来我将整个项目移植到XAML中,除了这个函数现在显示错误之外,其他一切基本上都一样。功能是:

Array<byte>^ LoadShader(std::string File){
    Array<byte>^ FileData = nullptr;
    std::ifstream VertexFile(File, std::ios::in | std::ios::binary | std::ios::ate);
    if(VertexFile.is_open()){
        int Length = (int)VertexFile.tellg();
        FileData = ref new Array<byte>(Length);
        VertexFile.seekg(0, std::ios::beg);
        VertexFile.read(reinterpret_cast<char*>(FileData->Data), Length);
        VertexFile.close();
    };
    return FileData;
};

它被放在一个头文件中,出现的3个错误是:

error C2143: syntax error : missing ';' before '<
error C2334: unexpected token(s) preceding '{'; skipping apparent function body
error C4430: missing type specifier - int assumed. Note: C++ does not support default-in

我只是不知道该怎么办……我已经检查了头文件的拼写是否正确,函数是Array<byte>^类型的,我确信我没有跳过头文件中唯一的主体函数。

如果我删除了这个函数,头文件就会工作,我只是感到困惑,不知道如何解决这个问题。作为参考,我会在下面发布完整的头文件(没有那么大)。

#pragma once
#include "DirectXHelper.h"
#include <fstream>

ref class DirectXBase abstract{
internal:
    DirectXBase();
public:
    virtual void Initialize(Windows::UI::Core::CoreWindow^ m_window, Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ m_panel);
    virtual void CreateDeviceResources();
    void CreateDepthStencil();
    void CreatePipeline();
    virtual void Render();
protected private:
    Array<byte>^ LoadShader(std::string File){
        Array<byte>^ FileData = nullptr;
        std::ifstream VertexFile(File, std::ios::in | std::ios::binary | std::ios::ate);
        if(VertexFile.is_open()){
            int Length = (int)VertexFile.tellg();
            FileData = ref new Array<byte>(Length);
            VertexFile.seekg(0, std::ios::beg);
            VertexFile.read(reinterpret_cast<char*>(FileData->Data), Length);
            VertexFile.close();
        };
        return FileData;
    };

protected private:
    Platform::Agile<Windows::UI::Core::CoreWindow> window;
    Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ panel;
    Microsoft::WRL::ComPtr<ID3D11Device1>          DXDevice;
    Microsoft::WRL::ComPtr<ID3D11DeviceContext1>   DXContext;
    Microsoft::WRL::ComPtr<IDXGISwapChain1>        SwapChain;
    Microsoft::WRL::ComPtr<ID3D11RenderTargetView> RTView; //Render Target View
    Microsoft::WRL::ComPtr<ID3D11DepthStencilView> DepthView; //3D Depth Stencil View
    Microsoft::WRL::ComPtr<ID3D11Texture2D>        DepthBuffer;
    Microsoft::WRL::ComPtr<ID3D11InputLayout>      InLayout;
    Microsoft::WRL::ComPtr<ID3D11VertexShader>     VShader; //Vertex Shader
    Microsoft::WRL::ComPtr<ID3D11PixelShader>      PShader; //Pixel Shader
};

Umm。您以前的使用是否可能在Array<byte>使用上方的文件中有using namespace Platform;

如果是这样的话,这就解释了为什么它不起作用。

最新更新