我的代码中出现了一些错误 [英] I got some errors in my code

查看:132
本文介绍了我的代码中出现了一些错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI Guyz ..请帮帮我。我有一个代码,但有一些错误...

这是一个代码。

  #include   <   oops.h  < span class =code-keyword>>  
#include < span class =code-string> standard.h
#include circular_buffer.h
#include linked_chunk.h

pool linked_chunk :: ThePool( sizeof ( linked_chunk));
pool cursor :: ThePool( sizeof (cursor));
char * linked_chunk :: version = Objects Plus Linked Chunk Version 1.0;
char * cursor :: version = Objects Plus光标版本1.0;

linked_chunk :: linked_chunk()
{
next = NULL;
storage = new circular_buffer();
}

linked_chunk :: ~linked_chunk()
{
next = NULL;
删除存储;

布尔 linked_chunk :: bounds(自然n)
{
return ((0< = n)&&(n< length()));>
};

linked_chunk * linked_chunk :: location(natural n)
{
natural l = storage-> length();
如果(n> = l){返回(下一个)? next-> location(n - l):NULL;};
返回 ;
}

natural linked_chunk :: length(){ return storage-> length()+(next?next-> ; length(): 0 ); };

Boolean linked_chunk :: full()
{
return false ;
};
Boolean linked_chunk :: empty(){ return storage-> empty()& &安培; (next?next-> empty(): true );
};

void * linked_chunk :: peak(natural n)
{
natural l = storage-> length( );
如果(n> = l){返回(下一个)? next-> peak(n - l):NULL;};
return storage-> peak(n);
}

void * linked_chunk :: get(natural n){
natural l = storage-> length ();
如果(n> = l){返回下一个? next-> get(n-l):NULL; }
return storage-> get(n);
}

void linked_chunk :: expand(自然n){

// 获取一个新的固定存储块并添加到此块的末尾
linked_chunk * c = new linked_chunk();
c-> next = next;
next = c;

if (n == 0 ){
circular_buffer * f = c->存储;
c-> storage = storage;
storage = f;
return ;
}

natural l = storage-> length();
自然限制=(l + 1)/ 2;
for (自然i = 0 ; i< = limit; i ++){
c-> storage-> set(i,storage-> get(limit));
}

}

void linked_chunk :: set(自然n, void * e){

// 这样做属于这里有空间吗?
natural l = storage-> length();
if ((!storage-> full())&&( 0 < = n)&&(n< = l)){
storage-> set(n,e);
return ;
}

// 它是否属于下一个块?
if ((n> = l)&&(next)){
next-> set(nl,e );
return ;
}

// 它是否属于数组的末尾?如果是这样,请腾出空间并存储
如果((n == l)&&(!next)){
next = new linked_chunk();
next-> set(n-l,e);
return ;
}

// 软件失败,超出界限,只需忽略
if ((n> l)&&(!next)){
返回;
}
// 腾出空间和商店
expand(n );
set(n,e);
}
void linked_chunk :: replace(自然n, void * e) {

// 这是块还是下一块呢?
natural l = storage-> length();
if (( 0 < = n)&&(n< l )){
storage-> replace(n,e);
return ;
}

// 这是块,替换这一个元素
if ((n> = l)&&(next)){
next-> replace(nl, e);
return ;
}

}
linked_chunk * linked_chunk :: shrink(){
if (empty() ){
linked_chunk * n = next;
delete ;
return (n?n-> shrink():NULL);
}
if (next)next = next-> shrink();
返回 ;
}

natural linked_chunk :: offset(linked_chunk * c)
{
if this == c) return 0 ;
return storage-> length()+(next?next-> offset(c): 0 );
}
布尔 linked_chunk :: test(){
布尔结果;
natural i;
linked_chunk * cp;
void * a [ 7 * CHUNK_SIZE];
自然长度;
布尔为空;
布尔已满;

results = true ;

// 简单创建和删除测试
cp = < span class =code-keyword> new linked_chunk();
length = cp-> length();
结果& =(长度== 0 );
delete cp;

// 存储所有nils并检查它们是否全部返回
// 测试集,峰值,长度,偏移量
cp = < span class =code-keyword> new linked_chunk();
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++){cp-> ; set(i,NULL);}
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++){results = results&& (NULL == cp-> peak(i));}
length = cp-> length();
结果& =(长度== 7 * CHUNK_SIZE);
natural base = cp-> offset(cp);
结果& =(base == 0 );
base = cp-> offset(cp-> next);
结果& =(base == cp-> storage-> length());
base = cp-> offset(NULL);
结果& =(base == cp-> length());

delete cp;

// 在每个单元格中存储更多唯一数据并检查
cp = new linked_chunk();
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++){
cp-> set(i,( void *)i);
a [i] = cp-> peak(i);
}
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++ ){
results = results&& (a [i] == cp-> peak(i));
}
length = cp-> length();
结果& =(长度== 7 * CHUNK_SIZE);
delete cp;

// 存储nils并检查,测试空,满,长
cp = new linked_chunk();
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++){cp-> ; set(i,nil);}
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++){results = results&& (NULL == cp-> peak(i));}
length = cp-> length();
结果& =(长度== 7 * CHUNK_SIZE);
empty = cp-> empty();
full = cp-> full();
results& =(empty == false );
结果& =(完整== false );
delete cp;
cp = new linked_chunk();
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++){
cp-> set(i,( void *)i);
a [i] = cp-> peak(i);
}
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++ ){
results = results&& (a [i] == cp-> peak(i));
}
length = cp-> length();
结果& =(长度== 7 * CHUNK_SIZE);
empty = cp-> empty();
full = cp-> full();
results& =(empty == false );
结果& =(完整== false );
delete cp;
void * e;
cp = new linked_chunk();
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++){
cp-> set( 0 ,( void *)i);
length = cp-> length();
结果& =(长度== 1 );
empty = cp-> empty();
full = cp-> full();
results& =(empty == false );
结果& =(完整== false );
e = cp-> get( 0 );
结果& = e ==( void *)i;
length = cp-> length();
结果& =(长度== 0 );
empty = cp-> empty();
full = cp-> full();
结果& =(空== true );
结果& =(完整== false );
}
delete cp;

cp = new linked_chunk();
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++){
cp-> set( 0 ,( void *)i);
}
length = cp-> length();
结果& =(长度== 7 * CHUNK_SIZE);
empty = cp-> empty();
full = cp-> full();
results& =(empty == false );
结果& =(完整== false );
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++){
e = cp-> get(cp-> length() - 1 );
结果& = e ==( void *)i;
}
length = cp-> length();
结果& =(长度== 0 );
empty = cp-> empty();
full = cp-> full();
结果& =(空== true );
结果& =(完整== false );
cp = cp-> shrink();
结果& =(cp == NULL);
delete cp;

cp = new linked_chunk();
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++)
{
cp-> set(i,( void *)i);
}
for (i = 0 ; i<( 7 * CHUNK_SIZE); i ++){
e = cp-> peak(i);
results& =(e ==( void *)i);
e = cp-> get(i);
results& =(e ==( void *)i);
cp-> set(i,( void *)( 2 * i)) ;
}
for (i = 0 ; i<( 7 * CHUNK_SIZE); i ++){
e = cp-> peak(i);
结果& =(e ==( void *)( 2 * i)) ;
}
length = cp-> length();
结果& =(长度== 7 * CHUNK_SIZE);
empty = cp-> empty();
full = cp-> full();
results& =(empty == false );
结果& =(完整== false );
delete cp;

// 计算列表中用于确定位置的块
cp = new linked_chunk();
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++)
{
cp-> set(i,( void *)i);
}
cursor * c;
linked_chunk * temp;
natural j;
for (i = 0 ; i< 7 * CHUNK_SIZE; i ++){
c = cp-> point( 0 ,i);
结果& =(c-> offset ==(CHUNK_SIZE)*(i /(CHUNK_SIZE)));
temp = cp;
j = i;
while (j> CHUNK_SIZE- 1 ){
temp = temp-> ;下一个 ;
j - = CHUNK_SIZE;
}
结果& =(c-> base == temp);
delete c;
}
delete cp;
返回结果;
}
cursor * linked_chunk :: point(自然偏移,自然n)
{
自然l = storage-> length();
if ((n> = l)&&(next)) return next-> point(offset + l,n - l);
cursor * c = new cursor();
c-> offset = offset;
c-> base = ;
return c;
};
cursor :: cursor()
{
offset = 0 ;
base = NULL;
};
cursor ::〜cursor()
{
offset = 0 ;
base = NULL;
};

解决方案

1。阅读*关于如何设置C ++项目和包含路径

2.阅读*关于如何使用声明和头文件

3.布尔值不是标准C / C ++类型,试试Bool



*:您可以在MSDN在线帮助中查看此信息,或者只是在网上搜索它。我可以提供更具体的建议,但如果你不学会自己查阅这些信息,你将永远不会学习如何编程,


它看起来编译器无法找到要包含在源文件中的头文件。可能你必须指定包含搜索路径(在命令行中或在 makefile 中或在 IDE )。

HI Guyz.. Please help me. I have a code and got some errors...
This is a code.

#include <oops.h>
#include "standard.h"
#include "circular_buffer.h"
#include "linked_chunk.h"

pool linked_chunk::ThePool (sizeof(linked_chunk)) ;
pool cursor::ThePool (sizeof(cursor)) ;
char * linked_chunk::version = "Objects Plus Linked Chunk Version 1.0" ;
char * cursor::version = "Objects Plus Cursor Version 1.0" ;
		
linked_chunk::linked_chunk()
{
	next = NULL ;
	storage = new circular_buffer() ;
}
	
linked_chunk::~linked_chunk()
{
	next = NULL ;
	delete storage ;
		
Boolean linked_chunk::bounds(natural n)
{ 
	return ((0<=n)&&(n<length()));>
};
		
linked_chunk * linked_chunk::location(natural n)
{
	natural l = storage->length() ;
	if (n >= l) {return (next) ? next->location(n - l):NULL;};
	return this;
}

natural linked_chunk::length() { return storage->length() + ( next ? next->length() : 0 ) ; } ;
	
Boolean linked_chunk::full()
{
	return false;
} ;	
Boolean linked_chunk::empty() { return storage->empty() && ( next ? next->empty() : true ); 
} ;
		
void *linked_chunk::peak(natural n)
{
	natural l = storage->length() ;
	if (n >= l) {return (next) ? next->peak(n - l) : NULL ;};
	return storage->peak(n) ;
}
		
void * linked_chunk::get(natural n) {
	natural l = storage->length() ;
	if ( n >= l ) { return next ? next->get(n-l) : NULL ; }
	return storage->get(n) ;
}
	
void linked_chunk::expand(natural n) {

	// get a new fixed chunk of storage and add to the end of this chunk
	linked_chunk * c = new linked_chunk () ;
	c->next = next ;
	next = c ;

	if (n == 0) {
		circular_buffer * f = c->storage;
		c->storage = storage ;
		storage = f ; 
		return ;
	}
	
	natural l = storage->length() ;
	natural limit = (l+1)/2 ;
	for(natural i=0 ; i<= limit ; i++ ) {
		c->storage->set(i,storage->get(limit));
	}
	
}
		
void linked_chunk::set(natural n,void * e) {

	// does it belong here and there is room?
	natural l = storage->length() ;
	if ((! storage->full()) && (0 <= n) && ( n <= l )) {
		storage->set(n,e);
		return;
	}
	
	// does it belong in the next chunk?
	if ((n >= l)&&(next)) { 
		next->set(n-l,e) ;
		return ; 
	}
	
	// does it belong at the end of the array? if so, make room and store
	if ((n == l)&&(!next)) { 
		next = new linked_chunk()  ;
		next->set(n-l,e) ;
		return ; 
	}
	
	// fail soft, out of bounds store, just ignore
	if ((n > l)&&(!next)) { 
		return ; 
	}
	// make room and store
	expand(n);
	set(n,e);	
}		
void linked_chunk::replace(natural n,void * e) {

	// is this the chunk or is it the next one?
	natural l = storage->length() ;
	if ((0 <= n) && ( n < l )) {
		storage->replace(n,e);
		return;
	}
	
	// this is the chunk, replace this one element
	if ((n >= l)&&(next)) { 
		next->replace(n-l,e) ;
		return ; 
	}
	
}		
linked_chunk * linked_chunk::shrink(){
	if (empty()) {
		linked_chunk * n = next ;
		delete this ;
		return (n ? n->shrink() : NULL) ;
	}
	if (next) next = next->shrink() ;
	return this;
}
		
natural linked_chunk::offset(linked_chunk *c)
{
	if (this==c) return 0;
	return storage->length() + ( next ? next->offset(c) : 0 ) ;
}		
Boolean linked_chunk::test(){
	Boolean results ;
	natural i;
	linked_chunk * cp ;
	void* a[7*CHUNK_SIZE] ;
	natural length;
	Boolean empty ;
	Boolean full ;
	
	results = true ;
	
	// simple create and delete test
	cp = new linked_chunk();
	length = cp->length();
	results &= (length==0) ;
	delete cp ;
	
	// store all nils and check to see if they all come back nil
	// test set,peak,length,offset
	cp = new linked_chunk();
	for(i=0;i<7*CHUNK_SIZE;i++) {cp->set(i,NULL) ;}
	for(i=0;i<7*CHUNK_SIZE;i++) {results = results && (NULL == cp->peak(i)) ;}
	length = cp->length();
	results &= (length==7*CHUNK_SIZE) ;
	natural base = cp->offset(cp) ;
	results &= (base==0) ;
	base = cp->offset(cp->next) ;
	results &= (base==cp->storage->length()) ;
	base = cp->offset(NULL) ;
	results &= (base==cp->length()) ;
	
	delete cp ;
	
	// store more unique data in each cell and check
	cp = new linked_chunk();
	for(i=0;i<7*CHUNK_SIZE;i++) {
		cp->set(i,(void *)i) ;
		a[i] = cp->peak(i) ;
	}
	for(i=0;i<7*CHUNK_SIZE;i++) {
		results = results && (a[i] == cp->peak(i)) ;
	}
	length = cp->length();
	results &= (length==7*CHUNK_SIZE) ;
	delete cp ;

	// store nils and check, test empty, full, length
	cp = new linked_chunk();
	for(i=0;i<7*CHUNK_SIZE;i++) {cp->set(i,nil) ;}
	for(i=0;i<7*CHUNK_SIZE;i++) {results = results && (NULL == cp->peak(i)) ;}
	length = cp->length();
	results &= (length==7*CHUNK_SIZE) ;
	empty = cp->empty();
	full = cp->full();
	results &= (empty == false) ;
	results &= (full == false) ;
	delete cp ;
	cp = new linked_chunk();
	for(i=0;i<7*CHUNK_SIZE;i++) {
		cp->set(i,(void *)i) ;
		a[i] = cp->peak(i) ;
	}
	for(i=0;i<7*CHUNK_SIZE;i++) {
		results = results && (a[i] == cp->peak(i)) ;
	}
	length = cp->length();
	results &= (length==7*CHUNK_SIZE) ;
	empty = cp->empty();
	full = cp->full();
	results &= (empty == false) ;
	results &= (full == false) ;
	delete cp ;
	void * e ;
	cp = new linked_chunk();
	for(i=0;i<7*CHUNK_SIZE;i++) {
		cp->set(0,(void *)i) ;
		length = cp->length();
		results &= (length==1) ;
		empty = cp->empty();
		full = cp->full();
		results &= (empty == false) ;
		results &= (full == false) ;
		e = cp->get(0);
		results &= e == (void *)i ;
		length = cp->length();
		results &= (length==0) ;
		empty = cp->empty();
		full = cp->full();
		results &= (empty == true) ;
		results &= (full == false) ;
	}
	delete cp ;

	cp = new linked_chunk();
	for(i=0;i<7*CHUNK_SIZE;i++) {
		cp->set(0,(void *)i) ;
	}
	length = cp->length();
	results &= (length==7*CHUNK_SIZE) ;
	empty = cp->empty();
	full = cp->full();
	results &= (empty == false) ;
	results &= (full == false) ;
	for(i=0;i<7*CHUNK_SIZE;i++) {
		e = cp->get(cp->length()-1);
		results &= e == (void *)i ;
	}
	length = cp->length();
	results &= (length==0) ;
	empty = cp->empty();
	full = cp->full();
	results &= (empty == true) ;
	results &= (full == false) ;
	cp = cp->shrink();
	results &= (cp == NULL);
	delete cp ;

	cp = new linked_chunk();
	for(i=0;i<7*CHUNK_SIZE;i++)
	{
		cp->set(i,(void *)i) ;
	}
	for(i=0;i<(7*CHUNK_SIZE);i++) {
		e = cp->peak(i) ;
		results &= (e == (void *)i) ;
		e = cp->get(i) ;
		results &= (e == (void *)i) ;
		cp->set(i,(void *)(2*i)) ;
	}
	for(i=0;i<(7*CHUNK_SIZE);i++) {
		e = cp->peak(i) ;
		results &= (e == (void *)(2*i)) ;
	}
	length = cp->length();
	results &= (length==7*CHUNK_SIZE) ;
	empty = cp->empty();
	full = cp->full();
	results &= (empty == false) ;
	results &= (full == false) ;
	delete cp ;
		
	// calculate the chunk in the list that materilizes the location
	cp = new linked_chunk();
	for(i=0;i<7*CHUNK_SIZE;i++)
	{
		cp->set(i,(void *)i) ;
	}
	cursor *c ;
	linked_chunk * temp ;
	natural j ;
	for(i=0;i<7*CHUNK_SIZE;i++) {
		c = cp->point(0,i) ;
		results &= (c->offset == (CHUNK_SIZE)*(i / (CHUNK_SIZE))) ;
		temp = cp ;
		j = i ;
		while (j> CHUNK_SIZE-1) {
			temp = temp->next ;
			j -= CHUNK_SIZE ;
		}
		results &= (c->base == temp);
		delete c ;
	}
	delete cp ;
	return results ;
}
cursor * linked_chunk::point(natural offset, natural n)
{
	natural l = storage->length() ;
	if ((n >= l)&&(next)) return next->point(offset+l, n - l) ;
	cursor * c = new cursor() ;
	c->offset = offset ;
	c->base = this ;
	return c;
};	
cursor::cursor()
{
	offset = 0 ;
	base = NULL ;
};	
cursor::~cursor()
{
	offset = 0 ;
	base = NULL ;
};

解决方案

1. read up* on how to set up a C++ project and include paths
2. read up* on how to use declarations and header files
3. Boolean is not a standard C/C++ type, try Bool

*: You can check either the MSDN online help for this info or simply search for it on the web. I could offer more specific advice, but if you don't learn to look up such information by yourself you'll never learn how to program either,


It looks the compiler is not able to find the header files you want to include in your source file. Probably you have to specify the include search path (in command line or in the makefile or in the projects settings exposed by your IDE).


这篇关于我的代码中出现了一些错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆