PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, August 13, 2022

[FIXED] How to call a function in C++?

 August 13, 2022     c++, function, output     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing