Sign in to follow this  
xfront

Header

Recommended Posts

I AM TRYING TO GET A BIT OF THE C++ but then I stop to a simplyest question in the world: how to make a function? I can begin like this: I want to make for example: int digit; digit = -14; if(digit >= 0)digit = digit; if(digit < 0)digit = digit * -1; And convert to this line: digit = function(digit) And I dont know how to make this but I know that that can be made by headers. PLZ help!

Share this post


Link to post
Share on other sites
You don't need a header for this.

A function in C++ looks like this:

return-type function-name( parameter-list ) {
code
}


So for example, the function you want might be:

int absolute( int x ) {
if( x >= 0)
return x;
if( x < 0 )
return x * -1;
}

This isn't necessarily the most optimal implementation of that function, simply the form that maps most closely to what you've provided. In fact there is a standard version of that function available to you (abs()).

It sounds like you're relatively new to C++ and don't have a firm grasp of some of the basic concepts (such as what a header file is and what it does) that are typically expected to be understood prior to working with functions and the like.

I recommend you Google for "Thinking in C++" and/or "C++: A Dialog." These are both free texts about C++ and are generally considered decent learning material. You should read them -- in particular their sections on functions. They will help you quite a bit.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
I recommend you Google for "Thinking in C++" and/or "C++: A Dialog." These are both free texts about C++ and are generally considered decent learning material. You should read them -- in particular their sections on functions. They will help you quite a bit.


Is Google a verb?

Anyway I know that header is a some sort of list of custom functions and the abs value was an exapmle. I created even a average value of entered in cmd following "C++ Beginner's Guide" but there was told "your not experienced for more complicated stuff" and the file ends :)

Share this post


Link to post
Share on other sites
Quote:
Original post by xfront
Anyway I know that header is a some sort of list of custom functions and the abs value was an exapmle.


Not really.

A header is a way of factoring out declarations of functions, as well as declarations or full definitions of types, in order to avoid writing them at the top of every translation unit.

Share this post


Link to post
Share on other sites
Quote:

Is Google a verb?

As a colloquial slang term, yes. "Google for X" is shorthand for "go to www.google.com and type X into the search box and hit enter." When you have to ask people to do that often, saving yourself the keystrokes helps. Google themselves apparently dislike the usage of their brand as a verb, but I value my wrists more than their pride.

It will produce for you, for example, this link.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this