C ++编程项目中的奇怪错误 [英] strange error in c++ programing project

查看:66
本文介绍了C ++编程项目中的奇怪错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在该程序中有一个奇怪的erorr,这是由于以下文件引起的,但在以下代码中我没有出现任何错误:

i have strange erorr in this programme wich i got it is because of the follwing filebut i can not get any mistake in the following code:

#include<iostream>
#include<string>
#include <stdlib.h>
#include"C:\users\shawki\desktop\sdright\clru.h"
#include "C:\users\shawki\desktop\sdright\IndexSpace.h"
#include"C:\users\shawki\desktop\sdright\stdafx.h"
#include"C:\users\shawki\desktop\sdright\CDPSpace.h"
#include"C:\users\shawki\desktop\sdright\Resource.h"
#include"C:\users\shawki\desktop\sdright\sd.h"

using namespace std;

#define COUNTER_BITS  (8)
typedef unsigned int (*hashfunc_t)(const char *);

 struct BLOOM {
    size_t asize;//size of bloom filter
    DWORD *a;//unsigned char *a;//pointer to the key value
    DATA_INDEX* PDATAINDEX[MAX_CACHE_DATA_INDEX_NUM];
    size_t nfuncs;//number of hash function
    hashfunc_t *funcs;//pointer for specific hash function
};



BLOOM *bloom_create(size_t size, size_t nfuncs, ...);//bloom filter constructor.
int bloom_destroy(BLOOM *bloom);//bloom filter destructor.
int bloom_increament(BLOOM *bloom, DWORD *s);//add new element to bloom filter function.
int bloom_decrement(BLOOM *bloom,DWORD *s);//delete new elements from bloom filter function.
int bloom_check(BLOOM *bloom, DWORD *s);//check the existence of value in bloom filter.

#endif



错误在哪里:



where the errore is :

1>------ Build started: Project: sd, Configuration: Release Win32 ------
1>  stdafx.cpp
1>C:\users\shawki\desktop\sdright\clru.h(18): error C2143: syntax error : missing ';' before '*'
1>C:\users\shawki\desktop\sdright\clru.h(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\users\shawki\desktop\sdright\clru.h(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



因此,请帮助我了解此错误的原因



so please help me to know the reason of this error

推荐答案

DWORD是Windows类型,必须包含windows.h或使用unsigned long.
谢谢.
DWORD is a windows type you must include windows.h or use unsigned long instead.
Regards.


您好,我已经解决了这个问题,它真的很简单,只需在BLOOM之前添加(struct)就太简单了,谢谢您的合作.但是我只想问一下您还有其他问题,我如何使这个BLOOM 4位计数器成为8位计数器,如我发布的第一个文件所示,其中它的源代码是bloom_filter.ccp,如下所示:

hi thank you i have solved the problem really it was so simple just add (struct) before BLOOM that was really too simple thank you for your cooperating.but i just want to ask you other question how can i make this BLOOM 4 bit counter it is 8 bit counter as it is shown in the first file i had posted where is the source code for it is bloom_filter.ccp is as follow:

#include<limits.h>
#include<stdarg.h>
#include<math.h>
#include<string.h>
#include"bloom_filter.h"
#include"clru.h"
#include"uthash.h"
#include"stdafx.h"
#include"CDPSpace.h"
#include"Resource.h"
#include"sd.h"
#include"./lib/md5.h"
  CBloom_Filter::CBloom_Filter(){
BLOOM *bloom=CBloom_Filter::bloom_create((size_t)ceil(0.5*1*1.44), 1,MD5String);
  }
  CBloom_Filter::~CBloom_Filter(){


  }

 BLOOM *CBloom_Filter::bloom_create(size_t size, size_t nfuncs, ...)//bloom filter constructor.
{
    BLOOM *bloom;
    va_list l;//variable refer to the expected parameter (…)
    int n;

    if(!(bloom = (BLOOM *)malloc( sizeof(BLOOM)))) return NULL;//to allocate memory for bloom filter when is there is no bloom filter return null.
    if(!(bloom->a=(unsigned char *)calloc((size*COUNTER_BITS+CHAR_BIT-1)/(CHAR_BIT), sizeof(char)))) {
        free(bloom);
        return NULL;
    }//to allocate array of memory a(which represents pointer for key value) when it is fail just free the bloom filter and return null.

    if(!(bloom->funcs=(hashfunc_t*)malloc(nfuncs*sizeof(hashfunc_t)))) {
        free(bloom->a);
        free(bloom);
        return NULL;


}//to allocate memory for pointer to specific hash function when it fails it free memory reserved by a(pointer to key) and bloom filter and return null.


    va_start(l, nfuncs);//this macro we use it in order to  initializes (l) variable for subsequent use by va_arg and va_end, and must be called first.
//The parameter (nfuncs) is  the  name  of  the  last  parameter before  the variable argument list, i.e., the last parameter of which the calling function knows the type.
//Because the address of  this  parameter  is  used  in  the va_start  macro,  it  should not be declared as a register variable, or as a function or an array type. The va_start macro returns no value.


    for(n=0; n<nfuncs; ++n) {
        bloom->funcs[n]=va_arg(l, hashfunc_t);// The va_arg macro expands to an  expression  that  has  the type  and  value  of  the  next argument in the call.  The parameter(l)  is the va_list l  initialized  by  va_start.
//Each  call  to  va_arg  modifies (l) so that the next call returns the next argument.  The parameter type is  a  type
//name  specified so that the type of a pointer to an object that has the specified type  can  be  obtained  simply  by adding a * to type. If there is no next argument, or if type is not compatible with the type of the actual  next  argument  (as promoted
//according  to  the  default  argument  promotions), random errors will occur.
//The first use of  the  va_arg  macro  after  that  of  the va_start  macro  returns the argument after last.  Successive invocations return the values of the remaining arguments.

    }
    va_end(l);// The va_end macro handles a normal return from the function whose variable argument list was initialized by  va_start.

    if (!(bloom->PDATAINDEX[0]=(DATA_INDEX*)malloc((MAX_DATA_INDEX_NUM)*sizeof(DATA_INDEX)))){
        free(bloom->PDATAINDEX);
        free(bloom->a);
        free(bloom);
        return NULL ;
    }
    bloom->nfuncs=nfuncs;
    bloom->asize=size;
    const char *s=(const char*)bloom->a;


    memset(bloom->a,0,(size*COUNTER_BITS+CHAR_BIT-1)/(CHAR_BIT));


    return bloom;
}

int CBloom_Filter:: bloom_destroy(BLOOM *bloom)
{
    free((void*)bloom->asize);
    free(bloom->a);
    free(bloom->PDATAINDEX);
    free((void*)bloom->nfuncs);
    free(bloom->funcs);
    free(bloom);

    return 0;
}

int CBloom_Filter:: bloom_increament(BLOOM *bloom, const char *s)//where (s)is pointer for the key value
{
    size_t n;

    for(n=0; n<bloom->nfuncs; ++n) {

    if  (bloom->a[((*(bloom->funcs[n]))(s))%(bloom->asize)]<225)
        bloom->a[((*(bloom->funcs[n]))(s))%(bloom->asize)]++;

    }

    return 0;
}
int CBloom_Filter:: bloom_decrement(BLOOM *bloom,const char *s)
{
    size_t n;

    for(n=0;n<bloom->nfuncs;++n){
        if (bloom->a[((*(bloom->funcs[n]))(s))%(bloom->asize)]>0)
        bloom->a[((*(bloom->funcs[n]))(s))%(bloom->asize)]--;


    }
    return 0;
}
int CBloom_Filter::  bloom_check(BLOOM *bloom, const char *s)
{
    size_t n;

    for(n=0; n<bloom->nfuncs; ++n) {
        if(bloom->a[((*(bloom->funcs[n]))(s))%(bloom->asize)]>=1)

        return true;//here we substitute with key value in each hash function checking each corresponding counter which is equal to 1 or not
        else
        return false;
    }


}


这篇关于C ++编程项目中的奇怪错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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