In this book I'm using, Sams Teach your self C++, it says to:

Start compiler,

choose file,

choose Win32 Console Application,

choose empty project,

choose C++ source file,

edit source code,

choose build,

check that you have know build errors and run the program.


Whats the difference betweeen Build and Compile?


Last question for the Hellow world program. It now wants me to leave out the ending brace and recompile to show an example of an error. However, I'm not sure if I should click on compile or build. I didn't click on compile before lol.
Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh! lol

Compile runs the preprocessor and then turns your source code into object code.

Building involves the above step but also the linker which links all the compiled object code together into one exe file.

>I'm not sure if I should click on compile or build.
A missing brace is a syntax error. You can get that during the compile stage, so either Compile or Build will work because Build compiles first, then links.

Thanks guys; now I know what they do. I'll use compile instead - since I'm working with one program. :)

Why doesn't this program work?

#include <iostream>

int main()
{
    using namespace std;

    cout << "In main\n";
    DemonstrationFunction();
    cout << "I'm back in main\n";
    return 0;
}

void DemonstrationFunction()

{
    std::cout << "In Demonstration Function\n";
}

If I put the funcion, DemonstrationFunction first, and the main() second, it works.

My head is starting to hurt lol.

You have to declare DemonstrationFunction.

I'm not sure what you meen lol. That is one of the two errors that pop up. In the book I'm working from, it looks like this and works.

#include <iostream>

void DemonstrationFunction()

{
    using namespace std;

    cout << "In Demonsration Function\n";
}

int main()
{
    using namespace std;

    cout << "In main\n";
    DemonstrationFunction();
    cout << "Back in main\n";
    return 0;
}

I just don't understand why it doesn't work when I write the main() first, then the Demonstration Function second.

You can only use a function if it's been declared first. That basically means that you tell the compiler "Hey you, compiler! This function exists. Let me use it now". When you write the body of a function, you're both declaring and defining it. If you don't want to define all of your functions before the functions that call them, use a prototype:

#include <iostream>

void DemonstrationFunction();

int main()
{
  using namespace std;

  cout << "In main\n";
  DemonstrationFunction();
  cout << "I'm back in main\n";
  return 0;
}

void DemonstrationFunction()
{
  std::cout << "In Demonstration Function\n";
}

And in the future, use code tags when posting code or I'll go Narue on your butt. ;)

Omg! It worked!

Narue, you is da best; thanks.

I didn't realize that any function that will be called on needs to be declared or defined first before the function that calls them. I like the prototype thingy; works nicely.

Man, this stuff is a whole knew language lol.

I guess declaring and defining a function in the begining, that will be used by another, is more proper?

My god, this is like a mind twister.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.