I was trying to make a program takes a filePath as std::string which is dependent upon basePath(path of my project) and a relative const path.
if I modify basePath then it doesnt reflect any change to filePath.
#include <iostream>
using namespace std;
string basePath = "C:\\Pime\\";
// main location of my project
string filePath = basePath + "folder\\";
// relative location in my project
int main() {
basePath = "D:\\Pime\\ ";
std::cout << filePath<< std::endl;
// prints-> C:\Prime\folder
return 0;
}
How to avoid this. Is Solution related to volatile keyword.