为什么相同的写法在不同的代码中报错?
  • 板块学术版
  • 楼主Masna_Kimoyo
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/7/9 16:00
  • 上次更新2023/11/3 10:54:17
查看原帖
为什么相同的写法在不同的代码中报错?
199459
Masna_Kimoyo楼主2023/7/9 16:00

截取替罪羊树中的一段://当然这是错的

struct node{
	int ls,rs;
	int val,tot,siz,del;
	node(){
		ls=rs=0;
		siz=tot=del=1;
	}
}t[N];
stack<int> st;
const double alpha=0.7;
int order[N];
int cnt,rt,Q;
inline bool notbalance(int p){
	if((double)t[p].siz*alpha<=(double)max(t[t[p].ls].siz,t[t[p].rs].siz))
		return 1;
	return 0;
}
inline void inorder(int p){
	if(!p)	return ;
	inorder(t[p].ls);
	if(t[p].del)	order[++cnt]=p;
	else	st.push(p);
	inorder(t[p].rs);
}
inline void update(int x){
	t[x].siz=t[t[x].ls].siz+t[t[x].rs].siz+1;
	t[x].siz=t[t[x].ls].tot+t[t[x].rs].tot+1;
}
inline void build(int &p,int l,int r){
	int mid=l+r>>1;
	p=order[mid];
	if(l==r){
		node(p); //一模一样的写法在这里
		return ;
	}
	if(l<mid)	build(t[p].ls,l,mid-1);
	if(l==mid)	t[p].ls=0;
	build(t[p].rs,mid+1,r);
	update(p);
}

然后提取出来相同写法

#include<bits/stdc++.h>
using namespace std;
struct node{
	int a,b,c;
	node(){
		a=1,b=2,c=3;
	}
}t[100];
inline void dfs(&x){
	node(x);
	return ;
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(),cout.tie();
	t[0].a=123;
	cout<<t[0].a<<endl;
	dfs(1);
	cout<<t[0].a<<endl;
	return 0;
}

后一个没法过编译

这是为什么啊?

2023/7/9 16:00
加载中...