L
liao6373
Unregistered / Unconfirmed
GUEST, unregistred user!
大家看看这一段很简单的代码:
class Test
{ private:
static int len;
public:
void Length();
};
void Test::Length()
{ len = 5;
}
int main()
{ return 0;
}
编译时没错,但连接时有错,解决该问题有两个方法:
[blue]方法一:[/blue]
class Test
{ private:
static int len;
public:
void Length();
};
[red]int Test::len;
[/red]//加入该行代码
void Test::Length()
{ len = 5;
}
int main()
{ return 0;
}
[blue]方法二:[/blue]
class Test
{ private:
static int len;
public:
void Length(){ len = 5;
}
};
int main()
{ return 0;
}
谁能告诉我这是为什么?
class Test
{ private:
static int len;
public:
void Length();
};
void Test::Length()
{ len = 5;
}
int main()
{ return 0;
}
编译时没错,但连接时有错,解决该问题有两个方法:
[blue]方法一:[/blue]
class Test
{ private:
static int len;
public:
void Length();
};
[red]int Test::len;
[/red]//加入该行代码
void Test::Length()
{ len = 5;
}
int main()
{ return 0;
}
[blue]方法二:[/blue]
class Test
{ private:
static int len;
public:
void Length(){ len = 5;
}
};
int main()
{ return 0;
}
谁能告诉我这是为什么?