c++ - void() issue - It doesn't print results -
i writing program split in 3 different files:
- 1) header named
my.h
; - a source cpp file named
my.cpp
; - the main file named
use.cpp
;
here statements:
/* header file my.h define global variable foo , functions print , print_foo print results out */ extern int foo; void print_foo(); void print(int);
/* source file my.cpp defined 2 funcionts print_foo() , print() , in called 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 is: " << << 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& = foo; = 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 program compiles , run correctly doesn't print supposed.
how can fix it?
thank you!
leo
to call function specifying return type not required. correct
void print_foo(); // declares function prototype
to
print_foo();
and
print(i); // pass argument
Comments
Post a Comment