星海's Blog

老头初学编程
QT tablModel/View编程中,QTABLEVIEW的视图大小问题

乱七八糟的入门知识

星海 posted @ 2011年3月24日 14:54 in C++学习 , 1801 阅读
extern std::string onestr("exercise 3.5a");

定义并初始化string类变量onestr,且初始化,因用了extern,只能出现在函数外部

除非特别声明,在全局作用域声明的const变量是定义该对象的文件的局部变量,不能被其他文件访问。可通过指定extern const使其他文件可以访问。

引用必须用同类型的对象初始化,且初始化后不能将该引用指向其他对象。

但const 引用则可以绑定到不同但相关的类型的对象或者右值。

int ival = 100;

int &iival = ival; //ok

int &errorss; //error

int &temp = 100; //error,must be an object, 但const int &temp = 100没有问题

const int ival = 234;

int &refval = ival //error,nonconst reference to a const object

string对象和字符串字面值连接时,+操作符的左右两侧至少要有一个是string对象

使用const_iterator类型时,得到一个迭代器,它所指向的元素的值不可以改变,但可以改变迭代器自身的值。
不要把它与 const vector<T>:iterator xxx弄混。 

两个迭代器相加的操作是未定义的


赋值表达式的值是其左操作数的值,其结果的类型是左操作数的类型。

习题5.19
假设ie 为vector<string>::iterator 类型的变量,指出下列表达式那些是合法的,并解释这些合法表达式的行为。
a,*iter++
b,(*iter)++
c,*iter.empty()
d,iter->empty()
e,++*iter
f,iter++->empty
【解答】
a、d、f合法。

    int x[10];
    int *p = x;
    cout << sizeof(x) / sizeof(*x) << endl;
    cout << sizeof(p) / sizeof(*p) << endl;


非CONST引用行参,只能与完全同类型的非const对象相联。
默认实参只能用来提供函数调用缺少的尾部实参。例如 xxxx函数有三个默认实参,则 xxxx(, , 'y')非法 


 

Avatar_small
Taro 说:
2011年4月26日 18:48

C++的语法不好惹……
路过

Avatar_small
Navodaya Result 2022 说:
2022年1月08日 18:47

The Jawahar Navodaya Vidyalaya (JNV) Samiti has also successfully completed the lateral entry admission selection tests for vacant seats of Class 7th, 8th, 9th, 10th, 12th Grade admission selection tests. A huge number of students are participated in lateral entry exam and the students are waiting to check JNV Result 2022 District Selected list Navodaya Result 2022 Class 6 along with waiting listed student details for all rural and urban area schools across in the state. Navodaya Vidyalaya Samity is announced the 5th to 6th Class Result for the listed regions or zones in district wise for all rural and urban area schools of the country in roll number wise along with the name of the student.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter