首页 文章
  • 1 votes
     answers
     views

    为什么const不适用于stl map的size(),而它适用于其他容器? [重复]

    这个问题在这里已有答案: Why isn't the [] operator const for STL maps? 6个答案 在处理一个难以在整体上解释/解释的问题时遇到,所以这里是问题的相关重构 . 用windows上的gnu g编译这段代码 int recreate(const map <int , vector<string> > &bitFieldMa...
  • 1 votes
     answers
     views

    使用std :: set实现稀疏3D网格时出错

    我正在尝试使用std :: set容器实现稀疏的3D网格,但我无法理解从编译器返回的错误,这是我正在尝试运行的最小示例: #include <iostream> #include <vector> #include <limits> #include <set> #include <Eigen/Core> using namespac...
  • 0 votes
     answers
     views

    无法将智能指针插入 Map

    我试图插入我的智能指针,p_pointer指向foo类进入map,但程序无法编译 . 因此,我试图使用普通指针foo *,程序确实编译 . 到目前为止,我已经能够像普通指针一样使用p_pointer而没有任何问题,所以我很惊讶这不起作用 . 如果有人能向我解释为什么这不起作用...... *此外,我已经发布在这里,人们抱怨我的代码之前是凌乱的 . 这次我使用了代码块功能“Format use As...
  • 0 votes
     answers
     views

    g编译器中包含的g函数

    can power函数用于计算像pow(200,200)这样非常大的值的功率 . 也可以用于long long int值... pow(long long int,long long int) . 我收到此错误/sources/tested.cpp:在函数'int main()'中: /sources/tested.cpp:16:错误:调用重载'pow(long long int&,long lo...
  • 0 votes
     answers
     views

    制作一个小型的个人WP插件,它正在为PHP添加空行

    我制作了一个小的WordPress插件来做与我网站相关的事情 . 每当我激活插件时,我的站点 Map 就会停止工作,因为插件正在向PHP添加空行,这会产生XML声明错误 . 这是我的插件的代码,任何人都可以检查代码,看看是什么导致了这个问题? <?php /* Plugin Name: Plugin Name Plugin URI: htt...
  • 45 votes
     answers
     views

    初始化初始化列表中unique_ptrs的容器因GCC 4.7而失败

    我试图以与Bjarne Stroustrup's C++11 FAQ中的示例等效的方式初始化_1166208: using namespace std; vector<unique_ptr<string>> vs { new string{"Doug"}, new string{"Adams"} }; // fails unique_...
  • 9 votes
     answers
     views

    C常量结构成员初始化

    我班上有一个不变的 struct timespec 成员 . 我该如何初始化它? 我得到的唯一疯狂的想法是派生我自己的 timespec 并给它一个构造函数 . 非常感谢! #include <iostream> class Foo { private: const timespec bar; public: Foo ( void )...
  • 0 votes
     answers
     views

    使用boost :: sregex_token_iterator时出错

    我想搜索正则表达式并用颜色打印 . 我使用boost :: sregex_token_iterator来做到这一点 . 这是我的代码 boost::regex re("ab."); string s=""; string buf; string infile("retest.txt"); //string ...
  • 2 votes
     answers
     views

    clang未能连接2线主功能程序

    我很容易得到clang,这就是当我尝试编译简单的2行程序时会发生的事情:(我在机器上有g,IDK,如果这是问题的原因) clang teststring.cpp -v Ubuntu clang version 3.0-6ubuntu3(tags / RELEASE_30 / final)(基于LLVM 3.0)目标:i386-pc-linux-gnu线程模型:posix“/ usr / bin ...
  • 17 votes
     answers
     views

    比较两个map :: iterators:为什么需要std :: pair的拷贝构造函数?

    下面编译和链接的非常简单的代码,而无需用C 98警告,但给出了用C 11模式不可理解的编译错误 . #include <map> struct A { A(A& ); // <-- const missing }; int main() { std::map<int, A> m; return m.begin() == m.end(...
  • -5 votes
     answers
     views

    如何从函数返回对?

    我正在尝试编写一个函数,它将从函数返回对,但我在编译时遇到错误 . This is the whole file: #include <iostream> #include <map> #include <utility> using namespace std; typedef pair<const string, const double> ...
  • -1 votes
     answers
     views

    插入到unordered_map中的类型转换问题[重复]

    这个问题在这里已有答案: C++11 make_pair with specified template parameters doesn't compile 1回答 我想要做的是在c类中基本上有一个键值存储,以便我可以通过键查找它的值 . 我一直在尝试使用unordered_map来执行类似于此的代码 . (我已经简化了一点,但你明白了) . #include <string>...
  • 583 votes
     answers
     views

    如何使用双括号或单括号,括号,花括号

    我对Bash中括号,括号,花括号的用法以及它们的双重或单一形式之间的区别感到困惑 . 有明确的解释吗?
  • 0 votes
     answers
     views

    Drupal使用数据提取创建报告

    我有一个Drupal网站,我想在管理菜单中添加一个页面,该表单将根据回答一些谜题的用户生成报告,并允许数据提取 . 我该如何继续创建表单并提出请求?我应该安装像CCK这样的模块来创建表单,然后使用另一个模块进行数据提取(在excel文件中)吗? 谢谢你的帮助 . 坦率
  • 1 votes
     answers
     views

    Drupal - 创建表单

    如何在drupal中创建一个包含大约5个文本字段的表单,允许用户输入数据,然后单击提交按钮并将其保存到mysql数据库表中?
  • 8 votes
     answers
     views

    使用setjmp在C对象上发出警告“可能会被破坏”

    #include <setjmp.h> #include <vector> int main(int argc, char**) { std::vector<int> foo(argc); jmp_buf env; if (setjmp(env)) return 1; } 用GCC 4.4.1编译上面的代码,g test.cc -Wextra -O1,...
  • 27 votes
     answers
     views

    GCC在初始化程序周围缺少括号

    我在C中有这个结构,我想初始化为零 . 如何摆脱缺失的括号警告? typedef struct { uint32_t incoming[FRAME_TYPE_MAX]; uint32_t outgoing[FRAME_TYPE_MAX]; uint32_t timeouts; uint32_t crc_errors; } pkt_t; static pkt_t s...
  • 50 votes
     answers
     views

    C 11:正确的std :: array初始化?

    如果我按如下方式初始化std :: array,编译器会给出一个关于缺少大括号的警告 std::array<int, 4> a = {1, 2, 3, 4}; 这解决了这个问题: std::array<int, 4> a = {{1, 2, 3, 4}}; 这是警告信息: missing braces around initializer for 'std::array...
  • 2 votes
     answers
     views

    当我聚合初始化数组而gcc没有聚合时,Clang警告我

    当我用CLANG编译以下代码时: #include <iostream> #include <array> #include <algorithm> #include <functional> int main() { std::array<int, 2> a = {1, 2}; std::array<int, 2>...
  • 8 votes
     answers
     views

    空括号调用默认构造函数或构造函数采用std :: initializer_list吗?

    以下是 Effective Modern C++ (第55页)的引用: “假设你使用一组空括号来构造一个支持默认构造函数的对象,并且还支持std :: initializer_list构造 . 你的空括号是什么意思?等等 . 规则是你得到默认构造 . ” 我用std :: array尝试过这个: std::array<int, 10> arr{}; 并得到g的警告(版本4.8.2...
  • 19 votes
     answers
     views

    当它们应用于构造函数时,在括号初始化列表中是否存在序列点?

    根据n4296 C标准文件: [dcl.init.list](8.5.4.4)(pg223-224)在braced-init-list的initializer-list中,initializer-clauses,包括pack扩展(14.5.3)产生的任何结果,都是按照它们出现的顺序进行评估 . 也就是说,与给定初始化子句相关联的每个值计算和副作用在每个值计算和副作用之前与在初始化列表的逗号分隔列...
  • 3 votes
     answers
     views

    为什么Clang警告缺少std :: array的大括号?

    我已经阅读了一些关于 -Wmissing-braces 的其他帖子: Is it wise to ignore gcc/clang's "-Wmissing-braces" warning? What's the correct way to initialize a member array with an initializer list? Brace elis...
  • 8 votes
     answers
     views

    在std :: unordered_map中使用对象引用作为键

    我想知道是否可以在C中的unordered_map容器中使用对象引用作为键 . #include <unordered_map> class Object { int value; }; struct object_hash { inline size_t operator()(const Object& o) const { return 0; } }; s...
  • 1 votes
     answers
     views

    GCC 4.1.1没有用tr1 :: unordered_map编译一些代码

    我有以下代码从一个更大的程序测试一个概念,我尝试在Linux上使用GCC 4.1.1进行编译 . 由于公司环境的限制,我不能使用更新版本的编译器,因此我必须编译并使用当前可用的编译器版本 . // test.cpp - my tr1::unordered_map usage example #include <iostream> #include <tr1/unordered_m...
  • 1 votes
     answers
     views

    为什么const成员导致错误?

    #include <vector> class B { }; class A { const std::vector<B> m_v; public: A(const std::vector<B>& v) : m_v(v) {} void doSomething() {} }; void foo(void* bar) { ...
  • 6 votes
     answers
     views

    WCF Web API中的HTTP缓存在浏览器中似乎不一致

    我正在使用_1166626实现一个简单的REST服务,并尝试设置HTTP标头以缓存响应 . 对于像这样的简单GET http://localhost:49302/my/2 响应标头如下所示: Server: ASP.NET Development Server/10.0.0.0 Date: Tue, 24 Jan 2012 18:18:44 GMT X-AspNet-Version: 4.0.3...
  • 0 votes
     answers
     views

    为什么在Coliru的Clang无法编译vector :: push_back?

    See it here.该计划非常平凡,就像这样: #include <vector> std::vector<int> bombs; int main() { bombs.push_back(42); // compile errors } 诊断对我来说没有多大意义: 在main.cpp中包含的文件中:1:在/usr/local/bin/../lib/gc...
  • 252 votes
     answers
     views

    如何让页脚停留在网页的底部?

    我有一个简单的2列布局,页脚可以清除标记中的左右div . 我的问题是我无法在所有浏览器中让页脚停留在页面底部 . 如果内容向下推动页脚,它就可以工作,但情况并非总是如此 . 更新: 它在Firefox中无法正常工作 . 当页面上没有足够的内容将页脚一直向下推到浏览器窗口的底部时,我在页脚下方看到一条背景颜色条 . 不幸的是,这是页面的默认状态 .
  • 4 votes
     answers
     views

    div为浏览器窗口的100%高度

    我的网站有两列,现在背景颜色在左栏的最后一段内容(用于导航)结束 . 我试过身高:100%,身高:100%;似乎没有用 . 这是css . .container { width: 100%; height:100%; min-width: 960px; background: #fbf6f0; margin: 0 auto; overflow: h...
  • 105 votes
     answers
     views

    如何强制Web浏览器不缓存图像

    背景 我正在为两个无偿网站编写和使用一个非常简单的基于CGI(Perl)的内容管理工具 . 它为网站管理员提供HTML表单,用于填写字段(日期,地点, Headers ,描述,链接等)的事件并保存 . 在该表单上,我允许管理员上传与事件相关的图像 . 在显示表单的HTML页面上,我还显示了上传图片的预览(HTML img标签) . 问题 当管理员想要更改图片时,会发生此问题 . 他只需点击“浏览”...

热门问题