vector<pair<string,double>>

Hi,
I wrote something like that:
1
2
3
4
5
6
#include <vector>
#include <utility>
class S : public class Number{
private:
	static std::vector<std::pair<std::string, double>> Zmienna::x;
}

rest of the code should not be important, I don't understand what i'm doing wrong
I have error:
Error 2 error LNK2001: unresolved external symbol "private: static class std::vector<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double>,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double> > > Zmienna::zbior" (?zbior@Zmienna@@0V?$vector@U?$pair@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@N@std@@V?$allocator@U?$pair@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@N@std@@@2@@std@@A) C:\Users\Szymon\Moje studia\C++\zad7\Zadanie\Wyrazenie.obj Zadanie
What is Zmienna:: for? You cannot change the scope of a member.

Your error is a linker error. You declared a static data member, it must be defined exactly once in the program (usually in the associated .cpp file).
Last edited on
Ok, I change this few minutes ago. But, without this that will be work?
Last edited on
I edited my post as you were reading it. Did you define the static data member exactly once in your program?
I dont know how should I do that properly.
1
2
3
4
5
6
7
//header (.hpp)
#include <vector>
#include <utility>
class S : public class Number{
private:
	static std::vector<std::pair<std::string, double>> x; //declaration
}
1
2
3
4
//source (.cpp)
#include "name of your header.hpp"

std::vector<std::pair<std::string, double>> S::x; //definition 
I love You LB!!!!
Everything works perfect.
Topic archived. No new replies allowed.