0

I'm learning C++, and the above code is returning: symbol(s) not found for architecture x86_64:

#include <iostream>

using namespace std;

class User {
    private:
        static int counter;
    public:
        int age;

        int getCounter() { return counter; }
};


int main() {
    User user;
    user.age = 22;

    cout << user.getCounter() << endl;
}

I'm learning from a Udemy course, and it should be working, since i'm just copying the content.

Thank you.

João Calvin
  • 193
  • 1
  • 2
  • 9
  • 3
    You're missing the definition of `int User::counter;` outside of the class. Static members need proper linkage. Any text on C++ (and I seriously mean any, no matter how bad) covering static class members covers this. If not, burn the book or DoS the site, and get something else. – WhozCraig Sep 02 '17 at 19:11
  • Congratulation, you found out that Udemy's quality usually sucks. – deviantfan Sep 02 '17 at 19:12
  • @deviantfan Do you have any C++ course to recommend it? – João Calvin Sep 02 '17 at 19:14
  • @JoãoCalvin As in "video" course or any other format like that? No, never. There are some acceptable books, but since I'm out of the phase where I need C++ books, I don't really keep up with new publications. Maybe you'll find something you like at https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – deviantfan Sep 02 '17 at 19:18
  • Anything it's acceptable, really. I will check it out this post, thank you for the help <3. – João Calvin Sep 02 '17 at 19:20

0 Answers0