Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make a function that writes something in the console, but I am unable to make that work. Here is the code:
#include <iostream>
using namespace std;
void test () {
	cout<<"test";
}
int main () {
	int test ();
}

Expected result: the word "test" appears in the console
Observed result: the console returns 0 without anything appearing in the console.

What I have tried:

Switching from int to void or changin the order of the functions seems to do nothing, and I have no idea of what the problem could be.
Posted
Updated 12-Jul-22 7:31am
v2

1 solution

I would say your code does not compile.
Try this ;)
C++
#include <iostream>
using namespace std;
void test () {
	cout<<"test";
}
int main () {
    // int test ();
	test ();
}
 
Share this answer
 
v2
Comments
Member 15704532 12-Jul-22 13:33pm    
why does this work
0x01AA 12-Jul-22 13:37pm    
Calling a method with a return value (int in that example) should be int result= test() . But in case the method does not have a return like void test() value you simply call it with test();.
[Edit]
Even a method returns e.g. int, but you are not interesting on that value you can invoke the method with test() [/Edit]

I hope it helps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900