在C ++中,多行注释以开头/*和结尾*/。
但是,如果发生以下情况,则会导致编译错误
/*
int a = 20;
/*
int b = 10;
*/
*/
Run Code Online (Sandbox Code Playgroud)
有什么原因为什么C ++不支持这种“嵌套注释”样式?
我正在做一个实验,通过多线程并发向MySQL表中插入数据。
这是 C++ 的部分代码。
bool query_thread(const char* cmd, MYSQL* con) {
if( !query( cmd, con ) ) {
return 0;
}
return 1;
}
int main() {
........
if(mysql_query(m_con, "CREATE TABLE tb1 (model INT(32), handle INT(32))") != 0) {
return 0;
}
thread thread1(query_thread, "INSERT INTO tb1 VALUES (1,1)", m_con);
thread thread2(query_thread, "INSERT INTO tb1 VALUES (2,2)", m_con);
thread thread3(query_thread, "INSERT INTO tb1 VALUES (3,3)", m_con);
thread1.join();
thread2.join();
thread3.join();
}
Run Code Online (Sandbox Code Playgroud)
但MySQL发出错误消息。
错误 cmd:插入 tb1 值 (1,1)
查询期间失去与 MySQL 服务器的连接
分段故障 …
最近我正在学习C++中的Link-List.这是我的代码:
#include <iostream>
using namespace std;
class Node{
Node* next;
int num;
public:
Node(int num){
this->num = num;
}
void connect(Node* next){
this->next = next;
}
Node* next_node(){
return next;
}
void COUT(){
cout<<this->num<<endl;
}
};
void swap(Node* n1,Node* n2){
static Node* n = n1;
n1 = n2;
n2 = n;
}
class List{
Node* head;
Node* last;
public:
List(){
head = 0;
last = 0;
}
void insert(Node* n){
if(head==0){
head = n;
last = n;
}
else{
last->connect(n); …Run Code Online (Sandbox Code Playgroud)