سؤال

I've been working on DirectX lately and I have a Array<byte>^ function to read the shaders in the program. The function works in a program I made like 3 days ago, but then I ported the whole project to work with XAML and everything works basically the same except that this function now shows errors. The function is:

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

It's placed in a header file and the 3 errors presented are:

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

And I just don't know what to do... I've checked correct spelling of the header file, the function is of Array<byte>^ type and I'm certain I didn't jump the only body function in the header file.

If I remove the function, the header file works and I'm just baffled and have no idea how to fix this. For reference I'll post the complete header file underneath (it's not that big).

#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. Is it possible that your previous use had a using namespace Platform; somewhere in the file above the use of Array<byte>?

If so that would explain why it's not working.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top