By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 (MSVS8) says "missing storage class or type
specifiers" when it tries to compile vector definition line.

Where's the problem? Thanks!

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
an************@yahoo.com 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 (MSVS8) 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

Jul 23 '05 #2

P: n/a
Sorry, it works... I just didn't mention "using namespace std;" at the
top to include vector definition.

Jul 23 '05 #3

P: n/a
an************@yahoo.com 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 (MSVS8) 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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.