简体   繁体   English

我正在尝试理解这两个代码块,有人可以帮忙吗?

[英]I am trying to understand these 2 blocks of code, could someone help please?

I am trying to understand some code and I was hoping someone could give me a basic overview of what this code means.我试图理解一些代码,我希望有人能给我这个代码含义的基本概述。 The first bit of code I don't understand is this:我不明白的第一段代码是这样的:

// loading file path
static string resourceRoot;
#define RESOURCE_PATH(p)  (char*)((resourceRoot+"/"+string(p)).c_str())

The second bit of code I am trying to fully understand is this:我试图完全理解的第二段代码是:

void Draw::loadMeshFromFile(cMesh* mesh,string name)
{
    bool fileload;
    resourceRoot = m_Path.toStdString();
    string str1 = "Head/";
    string str2 = ".3ds";
    fileload = mesh->loadFromFile(str1+name+str2);
    if(!fileload)
    {
        printf("Error - 3D Model failed to load correctly.\n");
        return;
    }

Any help would be truly appreciated.任何帮助将不胜感激。 I am trying to strengthen my programming, so I'd be glad for any response.我正在努力加强我的编程,所以我很高兴得到任何回应。 Thanks谢谢

The first part is a macro which helps you to create a path for a specified resource, relative yo some root resource path, you can set in your code.第一部分是一个宏,它可以帮助您为指定资源创建路径,相对于一些根资源路径,您可以在代码中设置。

You basically would use it like this:你基本上会像这样使用它:

static string resourceRoot;
#define RESOURCE_PATH(p) (resourceRoot+"/"+string(p))

void load(cMesh* mesh)
{
    // Probably set somewhere else
    resourceRoot = "/opt/resources";

    mesh->loadFromFile(RESOURCE_PATH("relarespath/myresource").c_str());
}

or或者

void load(cMesh* mesh)
{
    // Probably set somewhere else
    resourceRoot = "/opt/resources";

    string myresourcename = RESOURCE_PATH("relarespath/myresource");
    mesh->loadFromFile(myresourcename.c_str());
}

Since accessing the pointer in the original code is potentially dangerous, I removed it.由于访问原始代码中的指针存在潜在危险,因此我将其删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谁能给我解释一下这个 function,我无法理解 - Could anyone please explain me this function, I am not able to understand this 我从未见过的编译器错误有人可以帮助我理解它吗? - compiler error I've never seen could someone help me understand it? 请帮我理解这段代码背后的逻辑 - Please help me understand the logic behind this code 这是GFG的问题。 我正在尝试分析和理解这段代码 - This is a question from GFG. I am trying to analyse and understand this code 我正在尝试参考快速排序实现双 pivot 分区 function。 有人能帮我吗? - i am trying to implement the double pivot partition function in reference to quicksort. Can someone help me? 请帮助我了解在下面的代码中使用相同的命名空间 - Please help me understand the use of the same namespace in the code below 有人可以用结构解释这段代码吗? (试图学习Winsock 2) - Can someone explain this code with structs please? (trying to learn Winsock 2) 有人可以帮我理解stmdb,ldmia,以及如何用arm汇编语言实现这个C ++代码? - Can someone help me understand stmdb, ldmia, and how I can go about implementing this C++ code in arm assembly language? 有人可以帮我修改此代码。 我正在尝试显示棋盘格C ++ QT - can someone help me modify this code. I'm trying to Display a checkerboard C++ QT 我试图用这段代码找到二叉树的高度,但它一直返回 0,有人能告诉我为什么吗? - I am trying to find the height of a Binary tree with this code, but it keeps returning 0, can someone tell me why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM