草庐IT

c++ - 用户定义类型的 vector

尝试编译这段代码时:#include#includeusingnamespacestd;classTest{inta;public:Test(intpa):a(pa){}voidprint(){std::coutvet;vet.push_back(&t);return0;}gcc4.4.5-8报告各种错误,开始于:Infileincludedfrom/usr/include/c++/4.4/i486-linux-gnu/bits/c++allocator.h:34,from/usr/include/c++/4.4/bits/allocator.h:48,from/usr/include

c++ - 使用 c 函数时 C++ 中的命名空间

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:unresolvedoverloadedfunctiontypec++考虑下面的代码片段:#include#include#includeusingnamespacestd;voidtest(){std::stringstr="HelloWorld!";std::transform(str.begin(),str.end(),str.begin(),tolower);}关于tolower有错误使用G++编译时:未解析的重载函数。如果usingnamespacestd;已删除,代码工作正常。那么,我的问题是:n

c++ - 随机未在范围内声明

我收到错误:tester.cpp|20|error:'rand'wasnotdeclaredinthisscope|我是否遗漏了一些内容?voidtester::volumeset(boolA_B,inti,intv){if(A_B==true){A_volumn[i]=rand(v+1);}else{B_volumn[i]=rand(v+1);}} 最佳答案 random不是标准的C++函数;这是一个POSIX功能,因此它在Windows上不可用。使用rand相反,或者更好的是,新的C++11randomnesslibrary.

c++ - 未定义对析构函数的引用

我已经用C++编写了一些代码,但是当我尝试编译时,出现了一个非常奇怪的错误,这是我不应该出现的。这是我的代码:#includeusingnamespacestd;#include"articles.h"intmain(){//CréationdesarticlesconstStylos1("s1","Stylojade","Watertruc",500,"Noir");constRametter1("r1","Ramettehautequalité","Clairefont",95,80);//Créationdeslots(10%deréduction)constLotl1("l1"

C++ - 基类和私有(private)头文件

我正在用C++编写一个库,并且有一个像这样的类层次结构:message.h文件(在./mylib/src中)classMessage{};request.h文件(在./mylib/include/mylib中)#include"message.h"classRequest:publicMessage{};response.h文件(在./mylib/include/mylib中)#include"message.h"classResponse:publicMessage{};我希望对用户隐藏mylib/src文件夹中的所有内容,并且只想分发mylib/include中的文件。但问题是re

c++ - 在头文件和源文件中包含相同的 include derivate 是标准做法吗?

在使用say时,C++中的标准字符串类。你需要#include吗在头文件和源文件上?你能不能只拥有#include只在头文件上? 最佳答案 包含在头文件中可能表示类定义级别的依赖性(例如,您正在接受或返回字符串)。在这种情况下,您必须将include放在标题中;但是,如果您只在实现中使用字符串,则可能只需要在源文件中包含。 关于c++-在头文件和源文件中包含相同的includederivate是标准做法吗?,我们在StackOverflow上找到一个类似的问题:

c++ - C++ 中 100 位数字的平方根

'unsignedlonglong'最多可以求解15位数字。有没有办法找到100位数字的平方根? 最佳答案 您还可以使用Boost.Multiprecision库。这个库为一些流行的多精度实现提供了包装器。#include#include#include#includeintmain(){std::strings(100,'0');s.at(0)='1';boost::multiprecision::mpfr_float_100f(std::move(s));boost::multiprecision::mpfr_float_100

c++ - 无法从 std::shared_ptr <_Ty> 转换参数 1 (??)

在完成我的游戏原型(prototype)时,我遇到了这个错误,我以前从未见过。我试图将两个.cpp文件链接在一起,这个:#include#include"mage.h"#include"Warrior.h"#include"Rogue.h"#include"CharacterType.h"#include#include#include"Inventory.h"#include"blankEnemy.h"#include"Enemy.h"#include"Boss.h"#include#include#include"DeathMenu.h"#include"GameStart.h"#

python - SWIG Python undefined symbol 错误

我正在尝试使用SWIG创建一个*.so文件以便在Python中进一步使用,但有些东西不起作用。我有两个文件:数据收集器.h#include#include#include#include"gnublin.h"#includeclassdataGatherer{private:intthreshold;inttimeThreshold;intdata[4096];boolrunning;gnublin_spi*spiDevice;pthread_tspiThread;void*params;public:dataGatherer(void);dataGatherer(int,int);v

c++ - OpenGL 3.3/GLSL 和 C++ 错误 : "must write to gl_Position"

我目前正在尝试使用OpenGL3.3和C++以及GLM、GLFW3和GLEW库来渲染一个三角形,但在尝试创建我的着色器程序时出现错误。Vertexinfo(0):errorC5145:mustwritetogl_Position我已经尝试找出发生这种情况的原因并在其他论坛上询问过,但没有人知道原因是什么。这个错误可能起源于三个可能的点-在我的main.cpp中,我在其中创建窗口、上下文、程序、vao等......#include#include#include#include#include#include"util/shaderutil.hpp"#defineWIDTH800#def