Functions

OK so the next chapter in C++ how to program in our textbooks is intro to classes. I do think that additional functions should be mentioned beforehand. I have a good bit of experience in C programming, of course C doesn't have classes and isn't a programming language for objective projects. We need to note that functions are a critical part when creating classes. If you do not know about creating functions how will you be able to create classes?

So what function have we been working on thus far? Main() right? OK now we are going to go a step farther and create a new function and call upon that fuction withi main. There are two ways of doing this, you can use a process called Prototyping or you could put the desired function above the main function. 


#include

//Building fuctions


using namespace std;


//This is almost like building a class.
void World(){
cout <<"This is a example"</*Remember that the complier works from top to bottom there is another way of doing this.



}

int main()
{

    World(); //This calls the World function
    return 0;





}


With prototyping we do the same thing except:

#include

//Building fuctions


using namespace std;


//This is almost like building a class.
void World();

/*Remember that the complier works from top to bottom there is another way of doing this.
It is called prototyping*/
}

int main()
{

    World(); //This calls the World function
    return 0;
}


World(){ 
cout<<"This is prototyping"<
}    If you are having trouble thenewboston has a great video tutorial on this. Click here to go to that video.

No comments:

Post a Comment