static vector 
Author Message
 static vector

I want to use a static vector in my class
static vector<void *> vDataConn;

when i do this in a function(also static)
vector<void *>::iterator p2 = vDataConn.begin();

I get the linker error(below)
--------------------Configuration: ftpactivex - Win32
Debug--------------------
Compiling...
FTPClient.cpp
Generating Code...
Compiling...
ftpactivex.cpp
Generating Code...
Linking...
   Creating library Debug/ftpactivex.lib and object
Debug/ftpactivex.exp
FTPClient.obj : error LNK2001: unresolved external
symbol "private: static class std::vector<void *,class
std::allocator<void *> >  CFTPClient::vDataConn" (?


Debug/ftpactivex.dll : fatal error LNK1120: 1 unresolved
externals
Error executing link.exe.

ftpactivex.dll - 2 error(s), 0 warning(s)

What am i doing wrong?



Sat, 10 Dec 2005 09:54:58 GMT  
 static vector
I can't ensure it's a right way, but you can try it:
vector<void *>::iterator p2 = YOURCLASS::vDataConn.begin();

On the other hand, the static variable must be initialized.
--
kvls.


Quote:
> I want to use a static vector in my class
> static vector<void *> vDataConn;

> when i do this in a function(also static)
> vector<void *>::iterator p2 = vDataConn.begin();

> I get the linker error(below)
> --------------------Configuration: ftpactivex - Win32
> Debug--------------------
> Compiling...
> FTPClient.cpp
> Generating Code...
> Compiling...
> ftpactivex.cpp
> Generating Code...
> Linking...
>    Creating library Debug/ftpactivex.lib and object
> Debug/ftpactivex.exp
> FTPClient.obj : error LNK2001: unresolved external
> symbol "private: static class std::vector<void *,class
> std::allocator<void *> >  CFTPClient::vDataConn" (?


> Debug/ftpactivex.dll : fatal error LNK1120: 1 unresolved
> externals
> Error executing link.exe.

> ftpactivex.dll - 2 error(s), 0 warning(s)

> What am i doing wrong?



Sat, 10 Dec 2005 10:23:32 GMT  
 static vector

Quote:

> On the other hand, the static variable must be initialized.

    I believe you mean "The static variable must be defined".  Mentioniing
it inside the class declaration mean declares it.   IT must be separately
defined inside a CPP file.

--
Truth,
James Curran [MVP]
www.NJTheater.com     (Professional)
www.NovelTheory.com  (Personal)



Sat, 10 Dec 2005 11:17:56 GMT  
 static vector

Quote:

>I want to use a static vector in my class
>static vector<void *> vDataConn;

>when i do this in a function(also static)
>vector<void *>::iterator p2 = vDataConn.begin();

>I get the linker error(below)
>--------------------Configuration: ftpactivex - Win32
>Debug--------------------
>Compiling...
>FTPClient.cpp
>Generating Code...
>Compiling...
>ftpactivex.cpp
>Generating Code...
>Linking...
>   Creating library Debug/ftpactivex.lib and object
>Debug/ftpactivex.exp
>FTPClient.obj : error LNK2001: unresolved external
>symbol "private: static class std::vector<void *,class
>std::allocator<void *> >  CFTPClient::vDataConn" (?


>Debug/ftpactivex.dll : fatal error LNK1120: 1 unresolved
>externals
>Error executing link.exe.

>ftpactivex.dll - 2 error(s), 0 warning(s)

>What am i doing wrong?

You need to define static members as well as declare them. Do this in
the .cpp file, along side the member function definitions, like this:

vector<void*> CFTPClient::vDataConn;

Tom



Sat, 10 Dec 2005 17:39:33 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Static vector as member causes error?

2. VECTOR within a VECTOR

3. vector question when replacing array[10][20] with vectors

4. proper way of refering to pointer of vector to vector

5. Vector of vectors - compiler doesn't understand?

6. How to iterate through a vector of vectors?

7. Vectors Within Vectors

8. vector::pop_back and vector::erase leaking memory?

9. Problem initializing a vector of vectors

10. Static and non-Static member - Signature

11. Why there is no static destructor corresponding to static constructor

12. Creating a static class from non static Framework classes

 

 
Powered by phpBB® Forum Software