Hyperlinking programs.Urgent.

So. I've been working on this school assignment and I wanna know how I can hyperlink two cpp files.

For example,
if(condition==true){
hyperlink to true.cpp
cout<<"Please wait";
}

^ Is there a command to hyperlink or something.
Thanks in advance.
Never heard the word hyperlink being used for anything other than web links before.

It looks like you want to call a function. The function can be defined in another source file but you still need the function declaration before you can call it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// main.cpp

// This is a declaration of the foo function. 
// It's necessary because we need to tell the compiler about
// the function before we can call it in this source file.
void foo(); 

int main()
{
	if(condition==true){

		// Calls the foo() function.
		foo(); 

		cout<<"Please wait";
	}
}

1
2
3
4
5
6
7
// foo.cpp

// Here is the definition of the foo() function.
void foo()
{
	cout<<"I'm doing something...\n";
}


Often function declarations are put into header files. So if we have file foo.cpp it is common to have a file foo.h that we can include to use the functions in foo.cpp.

1
2
3
// foo.h

void foo();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// main.cpp

#include "foo.h"

int main()
{
	if(condition==true){

		// Calls the foo() function.
		foo(); 

		cout<<"Please wait";
	}
}

foo.cpp is the same as before.

The benefits of structuring the code like this becomes more apparent when you have many functions in the same file and many other files that includes them.
Last edited on
OMG. You are GOD. I love you man. Thank you so much.
You cleared my doubt so well. I wish I could tell the world abt you. YOU ARE AMAZINGGGG!
Glad I could help. :)
Topic archived. No new replies allowed.