unordered_map 错误 error: no match for ‘operator[]‘ in... <near match>

在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中不能使用 【】操作符

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值