更新时间:2023-02-15 20:02:15
gcc Calc.cpp -lstdc ++
错误信息:
Calc.cpp:在构造函数''Calc :: Calc()''中:
Calc.cpp:6:错误:在''this''中请求成员''a'',这是非
类类型''Calc * const''
Calc.cpp:7:错误:在''this''中请求成员'''',这是非
类类型''Calc * const''
Calc.cpp:在构造函数'Calc :: Calc(int,int)''中:
Calc.cpp:12:错误:请求成员''a' 'in''this'',这是非
类类型''Calc * const''
Calc.cpp:13:错误:请求成员' ''这''中的'b'',这是非b / b $ b $类类型''Calc * const''
Calc.cpp:在析构函数''Calc中::〜Calc()'':
Calc.cpp:18:错误:请求成员a中的''这个'',这是非
类类型''Calc * const''
Calc.cpp:19:错误:请求对于''这个''中的成员'''',这是非
类类型''Calc * const''
Calc.cpp:成员function''int Calc :: plus()'':
Calc.cpp:24:错误:在''this''中请求成员''a'',这是非
类类型''Calc * const''
Calc.cpp:24:错误:在''this''中请求成员''b'',这是非
类类型''Calc * const''
Calc.cpp:在成员函数''int Calc :: minus()''中:
Calc.cpp:29:错误:在''this''中请求成员'''',这是非'
类类型''Calc * const''
Calc.cpp:29:错误:在''this''中请求成员'''',这是非
类类型''Calc * const ''
Calc.cpp:我n成员函数''int Calc :: multi()'':
Calc.cpp:34:错误:在''this''中请求成员''a'',这是非 -
类类型''Calc * const''
Calc.cpp:34:错误:在''this''中请求成员''b'',是非b $ b类类型''Calc * const''
Calc.cpp:在成员函数''int Calc :: divide()'':
Calc.cpp:39:错误:在''this''中请求成员''b'',这是非b / b
类型''Calc * const' '
Calc.cpp:41:错误:在''this''中请求成员''a'',这是非'
类类型''Calc * const''
Calc.cpp:41:错误:在''this''中请求成员''b'',这是非
类类型''Calc * const''
Calc.cpp:45:错误:请求''这个'中的成员''''',这是非$ / $
类型''Calc * con st''
Calc.cpp:45:错误:在''this''中请求成员''a'',这是非'
class type' 'Calc * const''
我认为这些错误信息意味着''a''和'b''不是Calc
类的成员。为什么?
谢谢,
gcc Calc.cpp -lstdc++
Error Message:
Calc.cpp: In constructor ''Calc::Calc()'':
Calc.cpp:6: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:7: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In constructor ''Calc::Calc(int, int)'':
Calc.cpp:12: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:13: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In destructor ''Calc::~Calc()'':
Calc.cpp:18: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:19: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In member function ''int Calc::plus()'':
Calc.cpp:24: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:24: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In member function ''int Calc::minus()'':
Calc.cpp:29: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:29: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In member function ''int Calc::multi()'':
Calc.cpp:34: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:34: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In member function ''int Calc::divide()'':
Calc.cpp:39: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:41: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:41: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:45: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:45: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
I think those error messages mean ''a'' and ''b'' are not members of Calc
class. Why is that?
Thanks,
Alexander Dong Back Kim写道:
Alexander Dong Back Kim wrote:
亲爱的,
我以前一直使用C ++编程语言,但转到C#和
Java。几天前,我重新开始学习C ++,初学者心态非常好。我写了一个简单的类,gcc无法编译
类。有什么提示我不见了?
Dear all,
I used to use C++ programming language at all time but moved to C# and
Java. Few days ago, I restarted studying about C++ with a very
beginner''s mind. I wrote a simple class and gcc couldn''t compile the
class. Any hints that I''m missing?
查看编译器消息。 "这"是Calc * const类型,特别是
指针。你有这个的地方。你应该有this->。但是应该
这里是错误的词,因为你不需要使用this。在这里。
而不是this-> a = 0只需写a = 0。
Look at the compiler message. "this" is of type Calc* const, notably a
pointer. Where you have "this." you should have "this->". But "should"
is the wrong word here since you don''t need to use "this" at all here.
Rather than "this->a = 0" simply write "a = 0".
>
头文件:
#ifndef __Calc_h__
#define __Calc_h__
class Calc
{
private:
int a;
int b;
public:
Calc();
Calc (int a,int b);
~Calc();
int plus();
int minus();
int multi();
int divide();
};
#endif
源文件:
#include" Calc.h"
Calc :: Calc()
{
this.a = 0;
this.b = 0;
}
Calc :: Calc(int a,int b)
{
this.a = a;
this.b = b;
}
Calc ::〜计算()
{
this.a = 0;
thi sb = 0;
}
int Calc :: plus()
{
return this.a + this.b;
}
int Calc :: minus()
{
返回this.a - this.b;
}
int Calc :: multi()
{
返回this.a * this.b;
}
int Calc :: divide()
{
if(this.b!= 0)
{
返回this.a / this.b;
}
否则如果(a!= 0)
{
返回this.b / this.a;
}
其他
{
返回0;
}
}
GCC命令:
>
Header File:
#ifndef __Calc_h__
#define __Calc_h__
class Calc
{
private:
int a;
int b;
public:
Calc();
Calc(int a, int b);
~Calc();
int plus();
int minus();
int multi();
int divide();
};
#endif
Source File:
#include "Calc.h"
Calc::Calc()
{
this.a = 0;
this.b = 0;
}
Calc::Calc(int a, int b)
{
this.a = a;
this.b = b;
}
Calc::~Calc()
{
this.a = 0;
this.b = 0;
}
int Calc::plus()
{
return this.a + this.b;
}
int Calc::minus()
{
return this.a - this.b;
}
int Calc::multi()
{
return this.a * this.b;
}
int Calc::divide()
{
if (this.b != 0)
{
return this.a / this.b;
}
else if (a != 0)
{
return this.b / this.a;
}
else
{
return 0;
}
}
GCC command:
gcc Calc.cpp -lddc ++
>
错误消息:
Calc.cpp:在构造函数''Calc :: Calc()''中:
Calc.cpp:6 :错误:请求成员'a''在''this''中,这是非
类类型''Calc * const''
Calc.cpp:7:错误:请求对于''这个''中的成员'''',这是非
类类型''Calc * const''
Calc.cpp:在构造函数中''Calc :: Calc(int,int)'':
Calc.cpp:12:错误:在''this''中请求成员''a'',这是非
类类型''Calc * const''
Calc.cpp:13:错误:在''this''中请求成员''b'',这是非
类类型''Calc * const''
Calc.cpp:在析构函数''Calc :: ~Calc()''中:
Calc.cpp:18:错误:要求成员''a''在''this''中,这是非
类类型''Calc * const''
Calc.cpp:19:错误:在''this''中请求成员''b'',这是非b / b $ b $类类型''Calc * const ''
Calc.cpp:在会员傅nction''int Calc :: plus()'':
Calc.cpp:24:错误:在''this''中请求成员''a'',这是非
类类型''Calc * const''
Calc.cpp:24:错误:在''this''中请求成员''b'',这是非
类类型''Calc * const''
Calc.cpp:在成员函数''int Calc :: minus()''中:
Calc.cpp:29:错误:在''this''中请求成员'''',这是非'
类类型''Calc * const''
Calc.cpp:29:错误:在''this''中请求成员'''',这是非
类类型''Calc * const ''
Calc.cpp:在成员函数''int Calc :: multi()'':
Calc.cpp:34:错误:请求成员'' a''in''this'',这是非
类类型''Calc * const''
Calc.cpp:34:错误:请求成员''''在''这个' ,这是非
类类型''Calc * const''
Calc.cpp:在成员函数''int Calc :: divide()''中:
Calc.cpp:39:错误:在''this''中请求成员''''',这是非
类类型''Calc * const''
Calc.cpp:41:错误:在''this''中请求成员''a'',这是非
类类型' 'calc * const''
Calc.cpp:41:错误:请求''这个'中的成员'''',这是非
类类型''Calc * const''
Calc.cpp:45:错误:请求''这个'中的成员''''',这是非
类类型''Calc * const''
Calc.cpp:45:错误:在''this''中请求成员''a'',这是非
类类型''Calc * const''
我认为这些错误消息意味着''a''和'b''不是Calc的成员
cla SS。为什么?
谢谢,
gcc Calc.cpp -lstdc++
Error Message:
Calc.cpp: In constructor ''Calc::Calc()'':
Calc.cpp:6: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:7: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In constructor ''Calc::Calc(int, int)'':
Calc.cpp:12: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:13: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In destructor ''Calc::~Calc()'':
Calc.cpp:18: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:19: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In member function ''int Calc::plus()'':
Calc.cpp:24: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:24: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In member function ''int Calc::minus()'':
Calc.cpp:29: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:29: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In member function ''int Calc::multi()'':
Calc.cpp:34: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:34: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp: In member function ''int Calc::divide()'':
Calc.cpp:39: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:41: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:41: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:45: error: request for member ''b'' in ''this'', which is of non-
class type ''Calc* const''
Calc.cpp:45: error: request for member ''a'' in ''this'', which is of non-
class type ''Calc* const''
I think those error messages mean ''a'' and ''b'' are not members of Calc
class. Why is that?
Thanks,