0

I'm sorry I saw the error has been posted many times, but they didn't seem similar.

Error: public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > Class::path" (?path@Class@@2V?$basic_string@DU?$char_t

I was hoping I could run a function getPath that would take a file name and store it to a string. Somehow it doesn't work when using static?

class Class {
public:
    static std::string path;
    static void getPath();
};

void Class::getPath(PCWSTR FileName) {

    std::wcout << "FileName: " << FileName << std::endl;

    Class::path = "FileName";
}
jubibanna
  • 1,095
  • 9
  • 21
  • 2
    You need to define `path`. What you have is a declaration. – R Sahu May 22 '20 at 20:28
  • See the answer https://stackoverflow.com/a/12574407/434551 to the post marked as duplicate. – R Sahu May 22 '20 at 20:30
  • 1
    `static std::string path;` is a declaration, but not a definition. You need to add `std::string Class::path;` somewhere outside of, and after, the declaration of `Class` to actually define memory storage for `path`. – Remy Lebeau May 22 '20 at 21:21
  • Thanks, @Remy Lebeau. Fixed my problem! – jubibanna May 23 '20 at 04:24

0 Answers0