Hi, @Nikolas Fraser
The snippet needs the following modifications:
std:: is missing
Supplement the variable type when providing a definition for a global variable. Please check the doc: extern linkage for non-const globals
//fileA.cpp
int i = 42; // declaration and definition
Use Start() inside function.
Variable names are duplicated
Updated:
main.cpp
#include "globals.h"
#include"source.h"
#include<iostream>
//Start();
std::wstring someone = name;
std::wstring bob = L"Bob";
std::wstring name = bob;
void myFunction()
{
std::wstring bob = L"Bob";
name = bob;
//::name = bob;
std::wstring someone = name;
//std::wstring someone = ::name;
}
int main()
{
std::wcout << name<<std::endl;
foo();
std::wcout << name;
}
Source.h
#pragma once
void foo();
Source.cpp
#include<string>
extern std::wstring name;
void foo()
{
name = L"aaa";
}
Best regards,
Minxin Yu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.