【问题标题】:My Array<byte>^ function works in a previous project but not in a recent one我的 Array<byte>^ 函数在以前的项目中有效,但在最近的项目中无效
【发布时间】:2013-07-17 15:45:07
【问题描述】:

我最近一直在研究 DirectX,我有一个 Array&lt;byte&gt;^ 函数来读取程序中的着色器。该函数在我 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&lt;byte&gt;^ 类型,我确定我没有跳过唯一的正文函数头文件。

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

#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

};

【问题讨论】:

  • 您是否尝试过使用小写的“数组”?如array&lt;Byte&gt;^?

标签: xaml visual-c++ directx bytearray c++-cx


【解决方案1】:

嗯。您之前的使用是否有可能在Array&lt;byte&gt; 的使用上方的文件中某处有一个using namespace Platform;

如果是这样,那将解释为什么它不起作用。

【讨论】:

  • 非常感谢...我没有意识到头文件中没有 Platform 命名空间,而是将它放在 .cpp 文件中,在我看来它是去上班。无论如何,再次感谢我在这方面慢慢变得更好,并且远离我的第一个“Hello Worls”程序。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多