我一直在查看Boost库的源代码,我注意到通常只有单个符号没有附加任何预处理器指令.我阅读了GCC预处理器手册和规范指南,但没有找到任何相关信息.
(1) #ifndef BOOST_CONFIG_HPP
(2) # include <boost/config.hpp>
(3) #endif
(4) #
(5) #if defined(BOOST_HAS_PRAGMA_ONCE)
(6) # pragma once
(7) #endif
Run Code Online (Sandbox Code Playgroud)
在第4行,英镑符号后没有任何内容.这有什么影响?它是在C预处理器(CPP)规范中定义的吗?
由于Boost是一个跨平台的库,我认为任何CPP都应该正确解析它.在整个代码中使用随机井号/井号的影响/副作用是什么?
我编写了一个简单的 shell 脚本(称为test.sh)来使用两个不同的编译器(g++ 和 clang++)编译测试 C++ 文件,并放入一些echo语句来比较输出。在命令行上,我不小心输入了make test,即使该目录中没有 Makefile 。它没有抱怨没有 Makefile 或没有定义目标,而是执行了以下命令(我的系统正在运行带有 GNU Make 4.1 的 64 位 Debian Stretch 操作系统):
user@hostname test_dir$ make test
cat test.sh >test
chmod a+x test
user@hostname test_dir$
Run Code Online (Sandbox Code Playgroud)
对此感到好奇,我制作了另一个 shell 脚本 ( other.sh) 并做了同样的事情。
这是我的
other.sh文件:
#!/bin/bash
echo ""
echo "This is another test script!"
echo ""
Run Code Online (Sandbox Code Playgroud)
命令行:
user@hostname test_dir$ make other
cat other.sh >other
chmod a+x other
user@hostname test_dir$
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么在终端中运行命令时会make自动创建可执行脚本(不带.sh扩展名) ?make …
我正在玩constexprC++ 14及以上版本的构造函数,并注意到一些奇怪的东西.这是我的代码:
#include <iostream>
#include <string>
using std::cout;
using std::endl;
#define PFN(x) cout << x << __PRETTY_FUNCTION__ << endl
#define PF PFN("")
#define NL cout << endl
struct A {
constexpr A() { PF; }
virtual ~A() { PF; NL; }
};
struct B : A {
constexpr B() { PFN(" "); }
virtual ~B() { PFN(" "); }
};
int main(int argc, char** argv) {
{ A a; }
{ B b; }
A* a = new …Run Code Online (Sandbox Code Playgroud) 在这个页面上,它是写的
一个原因是删除的操作数不必是左值.考虑:
delete p+1;
delete f(x);
Run Code Online (Sandbox Code Playgroud)
这里,delete的实现没有指向它的指针.
在指针中添加一个数字会使它在内存中向前移动那么多个sizeof(*p)单位.
那么,delete p和之间的区别是什么delete p+1,以及为什么0只使指针成为问题delete p+1呢?
我正在查看有关成员引用运算符(一元*解引用运算符,->成员访问运算符)以及许多其他相关问题的C++标准:
ptr->你好();/*VERSUS*/(*ptr).hello();
我看到大多数答案都说p->m是(*p).mC++标准(5.2.5,第2段)定义的语法糖:
表达式
E1->E2转换为等效形式(*(E1)).E2
许多注释还指出,因为operator*并且operator->在类中是可重载的,所以它们应该均匀地重载以确保一致的行为.
这些陈述似乎相互矛盾:如果(根据标准)E1->E2转换为等效形式(*(E1)).E2,那么重载的目的是什么operator->(标准允许)?
更简单的说,标准的这两部分是冲突的,还是我误解了标准?
是否E1->E2等价转化为(*(E1)).E2适用于所有类型齐全或只建的呢?
似乎无法在此switch语句中找到语法错误.任何帮助深表感谢.
源代码:
import java.util.Scanner;
public class SwitchCasing {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
try {
int number = Integer.parseInt(input);
switch(number) {
case 1:
if(number < 0) {
System.out.println("Number is smaller than 0.");
break;
}
case 2:
if(number > 0){
System.out.println("Number is greater than 0.");
break;
}
default:
System.out.println("Number is 0.");
}
} catch(IllegalArgumentException e) {
System.out.println("Please insert a valid number.");
}
sc.close();
}
}
Run Code Online (Sandbox Code Playgroud)
无论输入什么值,输出始终为"数字为0".谢谢!