473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
3 1314
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
Sorry, it works... I just didn't mention "using namespace std;" at the
top to include vector definition.

Jul 23 '05 #3
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: klaas | last post by:
the following code gives rise to the beneath error message, only when a matrix object is instantiated as matrix<bool>, not with matrix<float>: /*returns a reference to the object at position...
2
by: Sean Dettrick | last post by:
Hi, apologies for yet another Singleton posting. From reading around previous postings etc, I've cobbled together two Singleton template definitions - one that returns a reference, and one that...
1
by: Alan Benn | last post by:
(VC6) When I use the STL <vector> template as follows: #include <vector> .... vector<CString> m_nameList; // Names of the chips I get these compiler warnings : C:\Program...
0
by: Jason Heyes | last post by:
I wrote a previous post that asked whether there was a reference-counted implementation of std::vector. Apparantly there wasn't. So my next question is, is it possible to write your own shared...
7
by: Gil | last post by:
trying to use a template in a vector, in Visual Studio 6 on Windows 2000 #include <vector> using namespace std; template <typename T> class AnyValue { T val;
10
by: Tony Johansson | last post by:
Hello Experts!! This class template and main works perfectly fine. I have this class template called Handle that has a pointer declared as T* body; As you can see I have a reference counter in...
13
by: imutate | last post by:
Hi, I am migrating some std::vectors to use a template instead, but I get an incomplete type error in a struct declaration. #include <vector> template < typename T > class Vec : public...
1
by: krunalbauskar | last post by:
Hi, Explicit instantiation of STL vector demands explicit instantiation of all the templates it using internally. For example - <snippet> #include <iostream> #include <vector>
3
by: nw | last post by:
Hi, I have three classes, a template pure virtual base class, a template derived class and a third which I would like to use to store copies of the derived class. The code looks like this: ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.