在const函数中使用[]访问出现奇怪错误
严重性 代码 说明 项目 文件 行 禁止显示状态
错误(活动) E0349 没有与这些操作数匹配的 “[]” 运算符 Opengl H:\VisualStudio\Opengl\Opengl\src\Shader.cpp 87
std::unordered_map<std::string, int> m_UniformLocationCache;
std::unordered_map<std::string, int> test;
unsigned int Shader::GetUniformLocation(const std::string &name) const
{
std::string s("zxs");
std::cout << test[s] << std::endl;
cout<<m_UniformLocationCache[z]<<endl;
if (m_UniformLocationCache.find(name) != m_UniformLocationCache.end()) {
//return m_UniformLocationCache[name];
//unsigned int cacheLocation=m_UniformLocationCache[name];
}
GLCall(unsigned int location= glGetUniformLocation(m_RendererId, name.c_str()));
if (location == -1){
std::cout << "Warning :uniform " << name << " doesn't exists"<<std::endl;
}
//m_UniformLocationCache[name] = location;
return location;
}
原因:const function中不能使用 【】操作符