C++ unresolved external symbol

前端 未结 4 1519
说谎
说谎 2021-01-12 21:04

Hi iam begginer at c++ i have class with static methods and i cant access them it throws me an error

    1>------ Build started: Project: CPractice, Confi         


        
4条回答
  •  心在旅途
    2021-01-12 21:42

    static string name;
    

    As it is static, this line only declares name - you need to define it too. Simply place this below your class definition:

    string CPractice::name;
    

    If you end up moving your class to a corresponding header and implementation file, make sure you place this definition in the implementation file. It should only be defined in a single translation unit.

提交回复
热议问题