問題のC++コードを書いていました。その後、私は同じ問題を解決できるCコードを書こうとしました。 ヘッダファイルBit.h
は次のとおりです。C++プログラムのエラー
#ifndef Bit_included
#define Bit_included
struct Bit
{
int width;
int value;
};
void init();
void initvalues(int v, int w);
void initcopy(const Bit& b);
int getWidth();
int getValue();
Bit & plus(int newval);
#endif //Bit_included
ファイルBit.c
は次のとおりです。ヘッダファイル内
#include "Bit.h"
#include "math.h"
using namespace std;
void init()
{
value=0;
width=0;
}
void initvalues(int v,int w)
{
value=v;
width=w;
}
void initcopy(const Bit& b)
{
value=b.value;
width=b.width;
}
int getWidth()
{
return width;
}
int getValue()
{
return value;
}
Bit & plus(int newval)
{
value+=newval;
if(value>=pow(2,width))
cout<<"Overflow";
return *this;
}
エラーは以下のとおりです。Bit.cで
Line 11: error: expected ';', ',' or ')' before '&' token
Line 14: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&' token
エラーは以下のとおりです。
Line 3: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
In function 'init':
Line 6: error: 'value' undeclared (first use in this function)
Line 6: error: (Each undeclared identifier is reported only once
Line 6: error: for each function it appears in.)
Line 7: error: 'width' undeclared (first use in this function)
In function 'initvalues':
Line 11: error: 'value' undeclared (first use in this function)
Line 12: error: 'width' undeclared (first use in this function)
t.c: At top level:
Line 14: error: expected ';', ',' or ')' before '&' token
In function 'getWidth':
Line 21: error: 'width' undeclared (first use in this function)
In function 'getValue':
Line 25: error: 'value' undeclared (first use in this function)
t.c: At top level:
Line 27: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&' token
正しいコードを書くにはどうすればよいですか?
'using namespace std;' ?? – UmNyobe
'C'には参照もありません。 – Mat
CはC++ではありません。 C++はC. – pmg