Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Using vector of references to a template class in the same template class.

Reply
Thread Tools

Using vector of references to a template class in the same template class.

 
 
Jonathan Bartlett
Guest
Posts: n/a
 
      02-08-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am trying to create a template class, which would store a vector of
> references to objects of the same class. Like:
>
> template<class _core_t>
> class Neuron
> {
> ///snipped
>
> private:
> vector<Neuron<_core_t>*> _neighbors;
> }
>
> But the compiler (MSVS says "missing storage class or type
> specifiers" when it tries to compile vector definition line.
>
> Where's the problem? Thanks!
>


Works fine with GCC. Probably a Microsoft problem. Or it could be your
missing semicolon at the end of the class definition. Or you could be
forgetting to #include <vector> or you could be forgetting to "using
namespace std;"

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017
 
Reply With Quote
 
 
 
 
andreykuzmenko@yahoo.com
Guest
Posts: n/a
 
      02-08-2005
I am trying to create a template class, which would store a vector of
references to objects of the same class. Like:

template<class _core_t>
class Neuron
{
///snipped

private:
vector<Neuron<_core_t>*> _neighbors;
}

But the compiler (MSVS says "missing storage class or type
specifiers" when it tries to compile vector definition line.

Where's the problem? Thanks!

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      02-08-2005
(E-Mail Removed) wrote:
> I am trying to create a template class, which would store a vector of
> references to objects of the same class.


Actually it's a vector of pointers.

> Like:
>
> template<class _core_t>
> class Neuron
> {
> ///snipped
>
> private:
> vector<Neuron<_core_t>*> _neighbors;
> }

;
>
> But the compiler (MSVS says "missing storage class or type
> specifiers" when it tries to compile vector definition line.
>
> Where's the problem? Thanks!


Did you include <vector> ? Did you write "using std::vector"? Does this
code:

#include <vector>
template<class X> class A {
std::vector<A<X>*> v;
public:
A() {}
};
int main() {
A<int> ai;
}

compile for you? If not, the problem is in Redmond, Washington state,
U.S.A. But that's one you cannot fix. If it compiles (as it should),
the problem elsewhere in your code.

Victor

 
Reply With Quote
 
andreykuzmenko@yahoo.com
Guest
Posts: n/a
 
      02-08-2005
Sorry, it works... I just didn't mention "using namespace std;" at the
top to include vector definition.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Initializing vector<vector<int> > and other vector questions... pmatos C++ 6 04-26-2007 05:39 PM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
how the vector is created, how to pass vector to webservices method apachesoap:Vector Rushikesh Joshi Perl Misc 0 07-10-2004 01:04 PM



Advertisments