为什么这是编译器错误? [英] why this is compiler error?
问题描述
C级{public:int i;};
C T;
T.i = 0; //为什么会出错?
int main()
{
int i = int();
返回0;
}
BTW:为什么这样一个:C测试(C())是声明一个函数(一个函数
,函数指针作为参数并返回一个C
类型的对象)?为什么它不是C对象的声明?
mi ********* @ gmail.com 写道:
class C {public :int i;};
CT;
Ti = 0; //为什么这是错误的?
因为它是任何函数的*可执行语句* _outside_。
>
int main()
{
int i = int();
返回0;
}
BTW:为什么这样一个:C测试(C())是声明一个函数(一个函数
带有一个函数指针作为其参数并返回C
类型的对象)?为什么它不是C的对象的声明?
因为这就是C ++语法规则的工作原理。如果你需要一个函数而不是一个对象,你会如何声明
a函数?
V
-
请在通过电子邮件回复时删除资金''A'
我没有回复最热门的回复,请不要问
mi ********* @ gmail.com napsal:
class C {public:int i;};
CT;
Ti = 0; //为什么这是错误的?
必须在某个函数内部。将它移动到main()并且它将起作用。
>
int main()
{
int i = int();
返回0;
}
BTW:为什么这样一个:C测试(C())是声明一个函数(一个函数
,函数指针作为参数并返回一个C
类型的对象)?为什么它不是C的对象的声明?
" Victor Bazarov D'μà£o
"
mi ********* @ gmail.com 写道:
class C {public:int i;};
CT;
Ti = 0; //为什么这是错误的?
因为它是任何函数的*可执行语句* _outside_。
int main()
{
int i = int();
返回0;
}
BTW:为什么这样一个:C测试(C())是声明一个函数(一个函数
,函数指针作为参数并返回一个C的对象
类型)?为什么它不是C的对象的声明?
因为这就是C ++语法规则的工作原理。你怎么声明
~~~~~~~~~~~~~~~~~~~~所以这只是因为
C ++语法?没有其他的
原因?
a函数如果你需要一个函数而不是一个对象?
V
-
请在通过电子邮件回复时删除资金''A'
我没有回复最热门的回复,请不要问
class C { public: int i;};
C T;
T.i = 0; //why it''s error?
int main()
{
int i=int();
return 0;
}
BTW: why such one : C test(C()) is to declare a function(a function
with a function pointer as its parameter and return an object of C
type)? why it is not a declare of an object of C?
mi*********@gmail.com wrote:class C { public: int i;};
C T;
T.i = 0; //why it''s error?Because it''s an *executable statement* _outside_ of any function.
>
int main()
{
int i=int();
return 0;
}
BTW: why such one : C test(C()) is to declare a function(a function
with a function pointer as its parameter and return an object of C
type)? why it is not a declare of an object of C?Because that''s how C++ syntax rules work. How would you declare
a function if you needed a function and NOT an object?
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
mi*********@gmail.com napsal:class C { public: int i;};
C T;
T.i = 0; //why it''s error?It must be inside of some function. Move it to main() and it will work.
>
int main()
{
int i=int();
return 0;
}
BTW: why such one : C test(C()) is to declare a function(a function
with a function pointer as its parameter and return an object of C
type)? why it is not a declare of an object of C?
"Victor Bazarov D′μà£o
"mi*********@gmail.com wrote:class C { public: int i;};
C T;
T.i = 0; //why it''s error?
Because it''s an *executable statement* _outside_ of any function.
int main()
{
int i=int();
return 0;
}
BTW: why such one : C test(C()) is to declare a function(a function
with a function pointer as its parameter and return an object of C
type)? why it is not a declare of an object of C?
Because that''s how C++ syntax rules work. How would you declare~~~~~~~~~~~~~~~~~~~~so it''s just because of
C++ syntax ?no other
reasons?a function if you needed a function and NOT an object?
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
这篇关于为什么这是编译器错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!