class C
{
public:
static virtual void foo() {}
void foo1() const {
value = 10;
}
void foo2() {
value = 10;
}
void foo3() {
std::cout << "hello world" << std::endl;
}
int value;
};
void foo(C* p) {
}
int main()
{
const C c;
c.foo1();
c.foo2();
c.foo3();
foo(&c);
C* p = NULL;
p->foo2();
p->foo3();
std::vector<int> v;
v.push_back(0);
int* p3 = &v.front();
for (int i = 0; i < 1024; ++i) {
v.push_back(i);
}
std::cout << *p3 << std::endl;
return 0;
}
// 把ipV4的地址,转化成一个绝对唯一的32位整数,即 ip 与 ipv4_to_uint32(ip) 是一一对应的,
// ip为点分十进制的地址,需要判断 ip 地址的合法性,当不合法时,抛出异常
// 1.111111111111111111111111111111111111111.1.1
unsigned ipv4_to_uint32(const std::string& addr)
{
vector<int>Q;
int x=0,f=0;
for(int i=0; i<addr.size(); i++)
{
if(addr[i]>='0'&&addr[i]<='9')
{
x=x*10+(addr[i]-'0');
f=0;
}
else if(addr[i]=='.'&&f==0)
{
Q.push_back(x);
x=0;
f=1;
}
else {
cout<<"error"<<endl;
return 0;
}
}
if(f==0)
Q.push_back(x);
else{
cout<<"error"<<endl;
return 0;
}
if(Q.size()!=4)
{
cout<<"error"<<endl;
return 0;
}
string S="";
(Q[0] << 24) | (Q[1]<<16) | (Q[2]<<8) | Q[3]
for(int i=0; i<4; i++)
{
if(Q[i]<0||Q[i]>255)
{
cout<<"error"<<endl;
return 0;
}
int x=Q[i];
string s="";
while(x)
{
s+=('0'+x%2);
x/=2;
//ans=ans*10+('0'+x%2);
}
reverse(s.begin(),s.end());
int l=s.size();
for(int i=l; i<8; i++)
{
s+='0';
}
S+=s;
}
long long ans=0;
for(int i=0; i<S.size(); i++)
ans=ans*10+(S[i]-'0');
return ans;
}
上面那段代码有多少错误?