← Back to Question List
C++ Code Walkthrough #82
Same Name, Different Namespace, Different File
📄 Code
Read carefully — what does this print?1// ===== mathx.h =====2#ifndef MATHX_H3#define MATHX_H45namespace seneca {6 int twice(int n);7 const int LIMIT = 3;8}910#endif1112// ===== mathx.cpp =====13#include "mathx.h"1415namespace seneca {16 int twice(int n) {17 return n * 2;18 }19}2021// ===== main.cpp =====22#include <iostream>23#include "mathx.h"24using namespace std;2526int twice(int n) {27 return n * 3;28}2930int main() {31 int total = 0;32 for (int i = 1; i <= seneca::LIMIT; i++) {33 total += seneca::twice(i);34 }35 cout << total << " " << twice(seneca::LIMIT) << endl;36 return 0;37}