Issue
so i tried making 2 functions and want to display both outputs and im new to C++ how do i fix this issue?
Code:
#include <iostream>
namespace first{
int x = 1;
}
namespace second{
int x = 2;
}
int main() {
using namespace first;
int x = 0;
std::cout << x << '\n';
std::cout << first::x << '\n';
std::cout << second::x << '\n';
return 0;
}
int lol() {
using namespace std;
using std::cout;
string lolipop = "hello world";
cout << lolipop << '\n';
return 0;
}
i want to display both outputs including hello world and the variables, variable are getting displayed in the output but not the second function the lol one.
Solution
You need to call lol()
.
Example:
int lol(); // forward declaration
int main() {
using namespace first;
int x = 0;
std::cout << x << '\n';
std::cout << first::x << '\n';
std::cout << second::x << '\n';
lol(); // calling lol
return 0;
}
Answered By - Ted Lyngmo Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.