草庐IT

INVALID_SCOPE

全部标签

c++ - 如何修复 "invalid operands to binary expression"错误?

我没有使用C++的经验,一直卡在编译器生成二进制表达式的无效操作数classAnimal{public:intweight;};intmain(){Animalx,y;x.weight=33;y.weight=3;if(x!=y){//dosomething}}我想使用x并与y进行比较,而不修改主代码中的代码,即(x.weight!=y.weight)。我应该如何从外部类或定义中解决这个问题? 最佳答案 或者,您可以将运算符重载添加为非成员:#includeusingnamespacestd;classAnimal{public:i

C++ 连接字符串导致 "invalid operands of types ‘const char*’ 和 ‘const char"

我想连接两个字符串,但出现错误,我不知道如何克服这个错误。有什么方法可以将这个constchar*转换为char吗?我应该使用一些取消引用吗?../src/main.cpp:38:error:invalidoperandsoftypes‘constchar*’and‘constchar[2]’tobinary‘operator+’make:***[src/main.o]Error1但是,如果我尝试以这种方式组成“bottom”字符串,它会起作用:bottom+="|";bottom+=tmp[j];bottom+="";这是代码。#include#include#include#inc

c++ - 这个私有(private)变量 "not declared in this scope"怎么样?

我目前正在尝试学习更多有关C++面向对象设计的知识(熟悉Java),但遇到了一些困难。我试图将这个项目放在一起,以在使用SFML构建图形和音频的游戏中学习这些原则。我有以下两个文件。WorldObject.h#ifndefWORLDOBJECT_H#defineWORLDOBJECT_H#include#include#include"ImageManager.h"classWorldObject{private:sf::Sprite_sprite;voidSetImagePath(std::stringpath);sf::SpriteGetGraphic();};#endif世界对象

git 免密登录/密钥失效/Missing or invalid credentials.

issuesMissingorinvalidcredentials.应该是原来创建的token过期了,直接执行步骤3即可1.创建token并拷贝到github1.cd~/.ssh2.ssh-keygen-trsa-C'xxxxx@qq.com'3.执行上一命令后会生成一下文件id_rsa和id_rsa.pub,将id_rsa.pub拷贝到githubnote:如果.pub文件已经存在,直接拷贝即可2.免密登录#设置git缓存#默认缓存15分钟gitconfig--globalcredential.helpercache#可以更改默认的密码缓存时限gitconfig--globalcredent

scope / 作用域(C变量的作用域)

scope/作用域(C变量的作用域)参考:CPrimerPlus第6版第12章存储类别、链接和内存管理目录scope/作用域(C变量的作用域)1.定义2.分类2.1.blockscope/块作用域2.1.1.定义2.1.2.函数的形式参数2.1.3.没有花括号的块2.2.functionscope/函数作用域2.3.functionprototypescope/函数原型作用域2.4.filescope/文件作用域3.总结1.定义描述程序中可以访问identifier(标识符)的区域2.分类scope可以分为四类:2.1.blockscope/块作用域2.1.1.定义block/块是用一块花括号

c++ - 在 Windows 7 上使用 SHA2-512 (CALG_SHA_512) 返回 "Invalid Algorithm Specified"

我尝试在Windows7上使用SHA2-512和CryptoAPI,但是,调用CryptCreateHash失败,GetLastError()=2148073480=0x80090008,即“无效算法”指定的”。根据https://msdn.microsoft.com/en-us/library/windows/desktop/aa375549%28v=vs.85%29.aspxSHA2应该从WindowsXPSP3开始可用。这是我使用的代码:HCRYPTPROVhCryptProv;CryptAcquireContext(&hCryptProv,nullptr,nullptr,PRO

c++ - 错误 MSB8008 : Specified platform toolset (v120) is not installed or invalid

这个问题在这里已经有了答案:WhatdoIneedtoinstallforC++project/VS2013onTeamCityserverorTeamFoundationBuildService?(1个回答)关闭8年前。我已经下载了一个C++项目。我打开了.sln文件并尝试构建项目。我收到以下错误:错误MSB8008:指定的平台工具集(v120)未安装或无效。请确保选择了受支持的PlatformToolset值。我已经检查过平台工具集是否设置为v120。这里有什么问题?

C++ 编译器错误 "was not declared in this scope"

我在尝试编译C++UDP客户端程序时遇到奇怪的编译器错误。g++-oclientUdp.cppClientMain.c-I.-lpthreadInfileincludedfromClientMain.c:1:0:Udp.h:Indestructor‘CUdpMsg::~CUdpMsg()’:Udp.h:103:43:error:‘free’wasnotdeclaredinthisscopeUdp.h:Inmemberfunction‘voidCUdpMsg::Add(in_addr_t,constvoid*,size_t)’:Udp.h:109:34:error:‘malloc’was

c++ - 错误 : invalid operands to binary % (have 'double' and 'double' )

我正在编写一个程序,其中列出了100,000个素数。它适用于10个数字,但在这么多数字之后它们变成负值。我将整数更改为长整数,但没有任何改变,然后我将它们更改为double,我得到了标题中列出的错误。我的变量应该是什么?请记住,我还是编程新手。我也看了一些以前的帖子,没有看到答案。intis_prime(doublex,chararray[]){//doesntusearraybutIputitintheredoublej=2;//dividerfor(j=2;j 最佳答案 您不能对运算符使用double,您必须使用int。你应该:

c++ - vector<auto> 是不允许的吗? (错误 : invalid use of ‘auto’ )

我有:#include#includeusingnamespacestd;intmain(){autoa=-SOME_CONST_MAX;vectormyVec{a,a,a,a};}我不知道SOME_CONST_MAX的类型但我想制作一个-SOME_CONST_MAX类型的vector.我假设vector会起作用,因为它会从a的类型推导出来.我正在运行这些错误:g++-std=c++14main.cppmain.cpp:9:9:error:invaliduseof‘auto’vectormyVec{a,a,a,a};^main.cpp:9:13:error:templateargume