About some really newbie question

1.GV() is okay. but how about GV2()?
If GV2 is unavailable.Is any possible make it like...Whay I am typing?
1
2
int GV(){ return 256; }
int GV2() return 512;


2.I realized some books wrote down
I can use one statement after one if statement
But why didnt work anymore?(Is just not working for me?)
1
2
3
4
int t1 = 10;
if(t1 == 10) int t2 = GV();
;Work only on some ... C++ Books...
;Or I am doing sth wrong...!?

1. You have to enclose the function body with curly brackets.

 
int GV2() { return 512; }

2. When you declare a variable inside an if statement like that the variable is only in scope inside that if statement. If you want to be able to use the variable after the if statement you should declare, and intitilize it to some default value, before the if statement and then use assignment inside the if statement instead.

1
2
3
4
int t1 = 10;
int t2 = 0;
if(t1 == 10) t2 = GV();
// Use t2 here... 

Last edited on
Sorry about my horrible English and more weird Questions.

But is any possible just make the
if statement or function become Python-Like ?

Because I really like the way how Python implement a funciton.
More clear ( But sometimes that will cause some FUZZY information)
But I like it !
So..Is any "Coding Style" or "Plug-in" can do the thing what I describing ?
e.g
--- C++
int funcA(){
...
return foo;
}
--- Py
funcA()
\t ...
\t return foo
*That's not necessary.But I still wanna ask more. Thanks !


info
IDE - VS2013
OS - MS Win8.1

Last edited on
1
2
3
funcA()
\t ...
\t return foo

dont you need the def keyword for python?
either way, there is hardly any difference.

If you want to write something like python, why not stick to python?
Uh...
Just because Python is really slow for huge computation.

And I think C++ still the main Program Lauguage in the world

Just thinking
If C++ can make the function prototype or any~
Just use the TAB to make it "readable"
(I am not talking C++ is not readable)
But compare with C++. Python is more clear.

I am not being rude...
Just try to figure out it's any method to make C++ coding like Python.
But compare with C++. Python is more clear.


I disagree :)

Initially new languages will be "less clear" compared to languages you know. I'm trying to learn some javascript at the moment and i hate it because it's not intuitive to me at all. But i realise it's because i'm not used to it. yet.
This is only my opinion by the way :)
Yeah
I'll try make me suitable about coding in C++.
Thanks for all answer!

I appreciate it!
Note that you can, and should, use tabs in C++ too. They might not be necessary but they make the code more readable, even for a C++ programmer.
Last edited on
Note that you can, and should, use tabs in C++ too. They might not be necessary but they make the code more readable, even for a C++ programmer.


Yeah I always make my code looks clear.
and add some space between variables

Thanks for your tips!
Readable is really important ~
Topic archived. No new replies allowed.