| | |
Static vector losing its contents
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 54
Reputation:
Solved Threads: 3
Hi guys,
I have a static vector which holds objects of a class. I want this vector to be singleton i.e. be the only vector of this type which will indefinitely store the relevant objects.
Unfortunately, a problem arises whereby, when I access the vector from a different class, for some reason it "loses" it's contents and is empty?
I have a static vector which holds objects of a class. I want this vector to be singleton i.e. be the only vector of this type which will indefinitely store the relevant objects.
Unfortunately, a problem arises whereby, when I access the vector from a different class, for some reason it "loses" it's contents and is empty?
0
#2 Nov 9th, 2009
>>a problem arises whereby, when I access the vector from a different class, for some reason it "loses" it's contents and is empty?
<<
From what content?
How about you make a adapter class, that wraps vector, and make that
adapter class singleton.
<<
From what content?
How about you make a adapter class, that wraps vector, and make that
adapter class singleton.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
•
•
Join Date: Oct 2009
Posts: 54
Reputation:
Solved Threads: 3
0
#3 Nov 9th, 2009
Hi there and thanks for the response. In the program, I navigate to an 'add book' GUI panel (A) which adds books to the vector. I then want to navigate to another panel (B) and populate a combobox using the contents of the vector. The vector remains populated in panel A but not B.
In short,
Home->Panel A->Home->Panel A the vector is fine
Home->Panel A->Home->Panel B then the vector appears empty
I tried to wrap the vector in a singleton class before trying to access the vBooks vector through the class as follows:
The code compiles fine apart from when I use the function 'push_back' which results in the following error:
error LNK2001: unresolved external symbol "public: static class std::vector<class Book,class std::allocator<class Book> > SingletonVector::vBooks" (?vBooks@SingletonVector@@2V?$vector@VBook@@V?$allocator@VBook@@@std@@@std@@A)
vc_mswd\myapp.exe : fatal error LNK1120: 1 unresolved externals
In short,
Home->Panel A->Home->Panel A the vector is fine
Home->Panel A->Home->Panel B then the vector appears empty
I tried to wrap the vector in a singleton class before trying to access the vBooks vector through the class as follows:
C++ Syntax (Toggle Plain Text)
class SingletonVector { public: static vector<Book> vBooks; SingletonVector() {}; };
C++ Syntax (Toggle Plain Text)
SingletonVector sv; Book b; b.setTitle("Test title"); sv->vBooks.push_back(b); // PROBLEM LINE
The code compiles fine apart from when I use the function 'push_back' which results in the following error:
error LNK2001: unresolved external symbol "public: static class std::vector<class Book,class std::allocator<class Book> > SingletonVector::vBooks" (?vBooks@SingletonVector@@2V?$vector@VBook@@V?$allocator@VBook@@@std@@@std@@A)
vc_mswd\myapp.exe : fatal error LNK1120: 1 unresolved externals
1
#4 Nov 9th, 2009
use SingletonVector::vBooks.push_back(b);
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
•
•
Join Date: Oct 2009
Posts: 54
Reputation:
Solved Threads: 3
0
#5 Nov 9th, 2009
Still no go..feels like the fix is not much further!
MainFrame.obj : error LNK2001: unresolved external symbol "public: static class std::vector<class Book,class std::allocator<class Book> > SingletonVector::vBooks" (?vBooks@SingletonVector@@2V?$vector@VBook@@V?$allocator@VBook@@@std@@@std@@A)
Reports.obj : error LNK2001: unresolved external symbol "public: static class std::vector<class Book,class std::allocator<class Book> > SingletonVector::vBooks" (?vBooks@SingletonVector@@2V?$vector@VBook@@V?$allocator@VBook@@@std@@@std@@A)
vc_mswd\myapp.exe : fatal error LNK1120: 1 unresolved externals
MainFrame.obj : error LNK2001: unresolved external symbol "public: static class std::vector<class Book,class std::allocator<class Book> > SingletonVector::vBooks" (?vBooks@SingletonVector@@2V?$vector@VBook@@V?$allocator@VBook@@@std@@@std@@A)
Reports.obj : error LNK2001: unresolved external symbol "public: static class std::vector<class Book,class std::allocator<class Book> > SingletonVector::vBooks" (?vBooks@SingletonVector@@2V?$vector@VBook@@V?$allocator@VBook@@@std@@@std@@A)
vc_mswd\myapp.exe : fatal error LNK1120: 1 unresolved externals
![]() |
Similar Threads
- Pointing to a vector (C++)
- Exception in deallocate using class vector (C++)
- Assigning a dynamic array to a vector (C++)
- list inside vector (Java)
- Creating two dimensional array (C++)
- Search problem (Java)
Other Threads in the C++ Forum
- Previous Thread: Program wont work (Need help with parameter passing)
- Next Thread: Writing PC programs on a Palm
Views: 283 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll dynamic encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort stream string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






