Code
#include<stdio.h>
int main()
{
int i;
printf("%d \n",'\1');
printf("%d \n",'\022');
printf("%d ",'\555');
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:1 18 109
当我们编译这个程序然后gcc编译器发出警告'\ 555'是八进制转义序列超出范围?这个范围是多少?
在以下代码中,在此行中
A(A&b)
使用此编译器时会出现错误
c110.cpp:41:错误:没有匹配函数来调用'A :: A(A)'
c110.cpp:8:注意:候选人是:A :: A(A&)
但只要我把它转换成
A(const A&b)
提前许多不止于此
没有错误.为什么会这样?
Code
class A
{
public:
static int cnt;
A(A& b)
{
cnt++;
cout<<"cnt="<<cnt<<endl;
}
A()
{
cnt++;
cout<<"cnt="<<cnt<<endl;
}
~A()
{
cnt--;
cout<<"cnt="<<cnt<<endl;
}
};
int A :: cnt=0;
A fun(A b)
{
return b;
}
int main()
{
A a;
A b=fun(a);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我对遗传的一些概念有疑问,我说的是我所知道的,如果我错了,请纠正我.
基类的私有成员由派生类继承,但派生类无法通过任何方式访问它们.
基类的受保护成员由派生类继承,但派生类不能直接访问它,而是通过其某些成员函数的帮助.
现在在以下代码中:
class A
{
protected:
A(const A&){}
A operator=(const A &){}
int t;
public:
A(int r) {t=r;}
A(){t=0;}
};
class B : public A
{
A a;
public:
void make(void)
{
//A b(a); //LINE 1 -------COPY CONSTRUCTOR BEING CALLED ---protected member of base class
cout<<t; //LINE 2 -------protected member of base class
}
};
int main()
{
B b;
b.make();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么LINE 1出现错误?
为什么我们不能为A的对象调用copy-constructor?
提前许多不止于此
我正在使用液体将一些数据格式化为文档.我正在获取变量的值并打印它,之后我想放置一个边界线.问题是,如果它是一行然后没有问题,但如果{{business.name}}扩展到几行,那么打印边界线就会出现问题,因为边界线在第一行之后打印.
我们如何确定变量的值延伸到几行或一行,以便我可以根据它放置边界线.
<div> {{ business.name }} </div>
<div class="border-top"> </div>
Run Code Online (Sandbox Code Playgroud) class X {
int i;
public:
X() { i = 0; }
void set(int ii) { i = ii; }
int read() const { return i; }
int permute() { return i = i * 47; }
};
Run Code Online (Sandbox Code Playgroud)
以上是X类的定义
另一个Y类是
class Y : public X {
int i; // Different from X's i
public:
Y() { i = 0; }
int change() {
i = permute(); // Different name call
return i;
}
void set(int ii) {
i = ii; …Run Code Online (Sandbox Code Playgroud) 在以下代码中
int& h() {
int o=100;
return o;
}
int main() {
int t=h(); //line 1
cout<<t; //line 2
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么输出为100,即函数的局部变量的值以及为什么第1行没有错误,因为函数的返回类型是int&但我们将其返回值返回到int.
可能的重复:
如何在 C++ 中逐行读取文件中的整数
请任何人都可以建议我如何在 C++ 中输入整数直到换行。
假设输入流是
10 10 10 10 10 10 10 10 10 10,然后是 C++ 中的换行符。
c++ ×5
inheritance ×2
c ×1
escaping ×1
html ×1
inputstream ×1
liquid ×1
octal ×1
overriding ×1
reference ×1