1
void () issue - Does not print results
source link: https://www.codesd.com/item/void-issue-does-not-print-results.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
void () issue - Does not print results
advertisements
I am writing a program split in three different files:
- 1) An header named
my.h
; - A source cpp file named
my.cpp
; - The main file named
use.cpp
;
Here their statements:
/* Header file my.h
Define global variable foo and functions print and print_foo
to print results out */
extern int foo;
void print_foo();
void print(int);
/* Source file my.cpp where are defined the two funcionts print_foo() and print()
and in where it is called the library std_lib_facilities.h */
#include "stdafx.h"
#include "std_lib_facilities.h"
#include "my.h"
void print_foo() {
cout << "The value of foo is: " << foo << endl;
return;
}
void print(int i) {
cout << "The value of i is: " << i << endl;
return;
}
/ use.cpp : definisce il punto di ingresso dell'applicazione console.
//
#include "stdafx.h"
#include "my.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int foo = 7;
int& i = foo;
i = 99;
char cc = '0';
while (cin >> cc) {
switch (cc) {
case '1':
void print_foo();
break;
case '2':
void print();
break;
default:
exit(EXIT_FAILURE);
}
}
return 0;
}
My main problem is that program compiles and run correctly but it doesn't print anything as I supposed.
How can I fix it?
Thank you!
To call a function specifying return type is not required. Correct
void print_foo(); // This actually declares a function prototype
print_foo();
print(i); // Pass i as argument
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK