Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我是否通过引用正确地传递和访问向量? 你好,我还是C++的新手,更喜欢SFML。我想知道在这个例子中,我是否可能有一个特定于向量的传递值/引用未匹配。 下面的似乎不起作用,我不知道为什么_C++_Sfml - Fatal编程技术网

我是否通过引用正确地传递和访问向量? 你好,我还是C++的新手,更喜欢SFML。我想知道在这个例子中,我是否可能有一个特定于向量的传递值/引用未匹配。 下面的似乎不起作用,我不知道为什么

我是否通过引用正确地传递和访问向量? 你好,我还是C++的新手,更喜欢SFML。我想知道在这个例子中,我是否可能有一个特定于向量的传递值/引用未匹配。 下面的似乎不起作用,我不知道为什么,c++,sfml,C++,Sfml,如果是一个微不足道的例子,请根据这里的内容道歉。我宁愿不粘贴项目代码的任何附加功能,因为这可能会使我的查询更加难以理解 -----类作用域全局变量,以前都在类构造函数中初始化,没有问题 string t1Path, t2Path, t3Path, t4Path, t5Path; vector<string> texturePaths = {t1Path, t2Path, t3Path, t4Path, t5Path}; sf::Texture t1, t2, t3, t4, t5;

如果是一个微不足道的例子,请根据这里的内容道歉。我宁愿不粘贴项目代码的任何附加功能,因为这可能会使我的查询更加难以理解

-----类作用域全局变量,以前都在类构造函数中初始化,没有问题

string t1Path, t2Path, t3Path, t4Path, t5Path;
vector<string> texturePaths = {t1Path, t2Path, t3Path, t4Path, t5Path};
sf::Texture t1, t2, t3, t4, t5;
vector<sf::Texture> textures = {t1, t2, t3, t4, t5};

如果有人想回答这个问题,非常感谢。

他们的尺码一样吗?@songyuanyao谢谢,是的。我有许多其他的传递参考功能,正如你在程序中所期望的那样,没有问题。你期望t1Path,t2Path等吗。。。若要在指定给TexturePath[i]?@S_BISHOP时更新,则看起来很好。“不行”是什么意思?提供一个将很有帮助。不直接相关,但不需要创建5个
sf::Texture
,将它们复制到
std::vector
中,然后再次销毁它们,您只需构建初始大小为5的
std::vector
,即std::vector sf::Textures(5)
void updateTexturePaths(vector<string>& tPathsRef) {    
   // or this ?   texturePaths = tPathsRef;
   for (size_t i = 0; i < textures.size(); i++) {
      texturePaths[i] = tPathsRef[i];
   }
}

playerPtr->updateTexturePaths(playerPtr->idlingRSpritePaths);
playerPtr->t1Path = playerPtr->idlingRSpritePaths[0];
playerPtr->t2Path = playerPtr->idlingRSpritePaths[1];
playerPtr->t3Path = playerPtr->idlingRSpritePaths[2];
playerPtr->t4Path = playerPtr->idlingRSpritePaths[3];
playerPtr->t5Path = playerPtr->idlingRSpritePaths[4];