回复:C++啊~~我的青春啊~~我哭,达人来帮忙看看吧!
不知道楼主想做什么。
这是我猜楼主的意思:
#include "stdafx.h"
#define NONIUS_NEXT (PosNonius++,Nonius->next)
#define NONIUS_PREV (PosNonius--,Nonius->prev)
#define NONIUS_HEAD (PosNonius = 0,head)
#define NONIUS_FOOT (PosNonius = Lenlist,foot)
#define NONIUS_NULL (PosNonius = 0,NULL)
typedef unsigned long ulong;
struct Node
{
ulong value;
Node *next,*prev;
}*head,*foot;
class TLK
{
private:
Node *Nonius;
ulong PosNonius;
void glideNonius(ulong position)
{
if(position>PosNonius)
{
while(position>PosNonius)
Nonius=NONIUS_NEXT;
}
else if(PosNonius>position)
{
while(PosNonius>position)
Nonius=NONIUS_PREV;
}
}
public:
TLK()
{
Nonius=head;
PosNonius=0;
}
ulong LKgetValue(ulong position)
{
glideNonius(position);
return Nonius->value;
}
void Print() const
{
printf("PosNonius=%d\n",PosNonius);
}
void IsNoniusEquals(Node *pnode) const
{
if(pnode==Nonius)
printf("Yes\n");
else
printf("No\n");
}
};
class TTR : private TLK
{
public:
TTR()
{
}
ulong TRgetChild(ulong ramusPos)
{
return LKgetValue(ramusPos);
}
void Print() const
{
TLK::Print();
}
void IsNoniusEquals(Node *pnode) const
{
TLK::IsNoniusEquals(pnode);
}
};
int main(int argc, char* argv[])
{
Node testNodes[10];
head=testNodes;
foot=testNodes+9;
for(int i=0;i<9;i++)
{
testNodes.next=testNodes+i+1;
testNodes[i+1].prev=testNodes+i;
testNodes.value=i;
}
testNodes[9].value=9;
TTR ttr;
printf("%d\n",ttr.TRgetChild(3));
ttr.Print();
ttr.IsNoniusEquals(testNodes+3);
return 0;
}
执行结果是:
3
PosNonius=3
Yes
没有错误。