我碰巧遇到了作者使用的C++ 11视频中的以下代码片段
auto main()->int
Run Code Online (Sandbox Code Playgroud)
我不明白这一点.我尝试编译g++使用-std=c++11,它的工作原理.有人可以向我解释这里发生了什么吗?我试图使用"auto main() - > int"进行搜索,但没有找到任何帮助.
有没有办法弄清楚input是buffered或unbuffered(除了手册页.)?我们不能通过查看函数的名称来弄清楚吗?也为echoing和nonechoing...
对于快速参考在哪里可以找到它具有细节的清单Buffered,Unbuffered,echoing和nonechoing投入?
我有两个问题......(我正在学习C,这可能是个愚蠢的问题.道歉)
根据如何在C语言和大多数书中声明字符串,即使你通过说分配内存,他们总是说声明一个字符串
char p2[] = "String";
Run Code Online (Sandbox Code Playgroud)我的问题是,无论如何要声明一个字符串?
根据/sf/answers/119310341/,在这样的示例中,
char s[]="hello";
Run Code Online (Sandbox Code Playgroud)放在只读区域,然后复制到数组.在C中打印字符串的地址是否有效?
printf("%p\n", &"Hello There"); // I tried, it prints some address
Run Code Online (Sandbox Code Playgroud)
并通过这样做
printf("%p\n", &"Hello There");
printf("%p\n", &"Hello There");
Run Code Online (Sandbox Code Playgroud)
它正在打印相同的地址.感觉是什么,它应该打印不同的地址.编译器在这里进行一些优化吗?
我正在阅读关于nullptrg ++和VS2010的锻炼和锻炼.
我什么时候做的
#include <iostream>
using namespace std;
auto main(void)->int
{
int j{};
int* q{};
cout << "Value of j: " << j << endl; // prints 0
cout << nullptr << endl;
cout << "Value of q: " << q << endl; // prints 0
return 0;
}
Run Code Online (Sandbox Code Playgroud)
打印nullptr屏幕上的值,g ++和VS给出了编译错误.是否不允许打印nullptr屏幕上的值?
6.7.6.3 Function declarators (including prototypes)
Run Code Online (Sandbox Code Playgroud)
这部分标准涉及'Identifier list'和'Parameter type list'.
首先,函数声明(非定义)与函数原型相同.我对么?如果这是对的,那么为什么标准会这样'including prototypes'说呢?
我无法理解函数声明'Identifier list'和'Parameter type list'函数声明之间的区别.
int fun(); // Declaration
int fun(int x)// Definition, but the signature doesn't match and it works.
{ return x; }
Run Code Online (Sandbox Code Playgroud)
有人可以解释,我很困惑?
6.2.5
在翻译单元内的各个点处,对象类型可能是不完整的(缺少足够的信息来确定该类型的对象的大小).
也
6.2.5 19)void类型包含一组空值; 它是一个不完整的对象类型,无法完成.
和
6.5.3.4 sizeof运算符不应用于具有函数类型或不完整类型的表达式,
但是,Visual Studio 2010页的打印0对
printf("Size of void is %d\n",sizeof(void));
Run Code Online (Sandbox Code Playgroud)
我的问题是'什么incomplete types'?
struct temp
{
int i;
char ch;
int j;
};
Run Code Online (Sandbox Code Playgroud)
是temp不完整吗?如果是,为什么它不完整(我们知道临时的大小)?没有清楚的想法incomplete types.解释此问题的任何代码段都会有所帮助.
按照这个/sf/answers/126905271/ writing one member of union and reading another member is undefined behavior.
并根据此/sf/answers/814842241/ type punning is allowed in C99 / C11
我对这两个帖子感到有点困惑,哪一个是正确的?需要帮助理解类型惩罚Vs访问union的成员.
谢谢.
需要帮助理解与类的“实现”关系。任何人都可以给我一个关于此的 C++ 示例吗?
我浏览了一下,发现实现接口的类就是一个实现的例子。我没有拍到更好的照片。我如何使用 UML 来表示相同的内容?
谢谢
§6.7.6.3函数声明符
2)在参数声明中出现的唯一存储类说明符是寄存器.
§6.7.6.3函数声明符
13)除非声明的参数是函数定义的参数类型列表的成员之一,否则将忽略参数声明的声明说明符中的存储类说明符(如果存在).
我已经宣布并定义了这样......
int function(static int param)
{
return param;
}
Run Code Online (Sandbox Code Playgroud)
Visual Studio正在发出警告.我所理解的是,如果我们register在函数声明中使用它作为参数类型,它应该在没有警告的情况下编译.除此之外register,它将忽略存储类并向用户发出警告消息.我的理解是否正确?
谢谢
我试图了解向下...这是我尝试过的......
class Shape
{
public:
Shape() {}
virtual ~Shape() {}
virtual void draw(void) { cout << "Shape: Draw Method" << endl; }
};
class Circle : public Shape
{
public:
Circle(){}
~Circle(){}
void draw(void) { cout << "Circle: Draw Method" << endl; }
void display(void) { cout << "Circle: Only CIRCLE has this" << endl; }
};
int main(void)
{
Shape newShape;
Circle *ptrCircle1 = (Circle *)&newShape;
ptrCircle1->draw();
ptrCircle1->display();
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
在这里,我通过将基类指针转换为派生类来进行向下转换.我的理解是......
Circle* ptrCircle1 --> +------+ new Shape()
|draw()| …Run Code Online (Sandbox Code Playgroud)