C++ “原因”;错误:sizeof';x';是未知或零“;在C++;?
我是编程的初学者。不幸的是,我有一个C++项目,我不知道它的问题。程序有点长:C++ “原因”;错误:sizeof';x';是未知或零“;在C++;?,c++,compiler-errors,C++,Compiler Errors,我是编程的初学者。不幸的是,我有一个C++项目,我不知道它的问题。程序有点长: #include <iostream.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <alloc.h> #include <time.h> #include <math.h> #include "vdsim.h" void gen01dat(
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <time.h>
#include <math.h>
#include "vdsim.h"
void gen01dat( long, int);
void cnv_encd(int g[], long,int,int);
int main()
{
long data_len=10;
int *out_array;
long input_len=5;
int g[2][3];
void gen01dat(data_len,*out_array);
int in_array=*out_array;
void cnv_encd(g,input_len,in_array,*out_array);
cout<<"the out_array 2 is :\t"<<*out_array<<endl;
void gen01dat( long data_len, int *out_array ) {
long t; /* time */
/* re-seed the random number generator */
randomize();
/* generate the random data and write it to the output array */
for (t = 0; t < data_len; t++)
*( out_array + t ) = (int)( rand() / (RAND_MAX / 2) > 0.5 );
}
void cnv_encd(int g[2][k],long input_len, int *in_array,int *out_array)
{
int m; /* K - 1 */
long t, tt; /* bit time, symbol time */
int j, k; /* loop variables */
int *unencoded_data; /* pointer to data array */
int shift_reg[K]; /* the encoder shift register */
int sr_head; /* index to the first elt in the sr */
int p, q; /* the upper and lower xor gate outputs */
m = K - 1;
/* read in the data and store it in the array */
for (t = 0; t < input_len; t++)
*(unencoded_data + t) = *(in_array + t);
/* zero-pad the end of the data */
for (t = 0; t < m; t++) {
*(unencoded_data + input_len + t) = 0;
}
/* Initialize the shift register */
for (j = 0; j < K; j++) {
shift_reg[j] = 0;
}
sr_head = 0;
/* initialize the channel symbol output index */
tt = 0;
for (t = 0; t < input_len + m; t++) {
shift_reg[sr_head] = *( unencoded_data + t );
p = 0;
q = 0;
for (j = 0; j < K; j++) {
k = (j + sr_head) % K;
p ^= shift_reg[k] & g[0][j];
q ^= shift_reg[k] & g[1][j];
}
/* write the upper and lower xor gate outputs as channel symbols */
*(out_array + tt) = p;
tt = tt + 1;
*(out_array + tt) = q;
tt = tt + 1;
sr_head -= 1; /* equivalent to shifting everything right one place */
if (sr_head < 0) /* but make sure we adjust pointer modulo K */
sr_head = m;
}
/* free the dynamically allocated array */
free(unencoded_data);
}
return 0;
}
我不知道这个错误是什么意思?
感谢您的帮助,不能在C++中嵌套函数,所以尝试移动<代码> CNVYEngEnter()/<代码>和<代码> GENO1DATA()/<代码> < <代码>主体()> <代码> < < 此外,您错误地调用了函数:
void gen01dat(data_len,*out_array);
应该是
gen01dat(data_len,out_array);
而且在使用前,您不会初始化out\u array
(这不是编译错误,但会使程序崩溃)
您对
cnv_encd()
的调用也同样错误。您还可以声明cnv_encd()
以在不同的位置使用不同的参数:将main()
之前的声明与您稍后给出的定义进行比较。您尝试在main中调用gen01dat&cnv_encd函数。但是,您的调用语法是错误的
void gen01dat(数据列,*输出数组)
应该是
gen01dat(数据列,*输出阵列)
另一个函数调用也是如此
查看您的代码,即使在修复这些代码之后,您也会遇到其他警告或错误。但既然你在学习,我就让你自己去弄清楚
更新:我没有在main中看到嵌套函数。这也是错误的。不过,我怀疑缺少的右大括号是一个输入错误。只有在声明函数时才使用“void”关键字。它告诉编译器此函数不返回任何值
因此,您只能在声明函数和实现函数时使用它。当你调用它们时,你只需要使用它的名称和参数。就像Aditya Sehgal指出的那样
您需要更改您的声明。它们必须包含参数变量名,而不仅仅是变量的类型。事实上,我认为这是函数的定义,不是对它们的调用。#includes后面有一个声明,所以我想他理解声明是什么。然后他试着通过给出实际参数来调用IMO。实际的定义有点下移。如果您看到代码,我认为OP只是缺少一个表示main结束的右括号
main()
的code>和右大括号位于其他两个函数的定义之后。我们也可以在调用函数时使用“void”。类似于(void)Function()的东西;我不知道发布的代码是如何产生这些错误消息的,尽管这有点难说!。请重新编译并重新发布完整的错误消息,其中包含发生错误的行号。
gen01dat(data_len,out_array);