473,769 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1347
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
4145
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 (Row,Col) in matrix*/ template <class num_type,template <class T> class functor> num_type & matrix<num_type,functor >::operator()(const int Row,const int Col) {if (Row<rows && Col<cols) {vector<num_type> & x=matrix_core; //num_type & y=x;<-is also...
2
5876
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 returns a pointer. I understand the pointer one and it works, but the reference one doesn't work as I expect. Can anybody explain this to me? (Code below). I'm not really looking for thread safety or for something as general
1
5917
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 Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(39) : warning C4100: '_P' : unreferenced formal parameter
0
1596
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 container that behaves like std::vector? Here is me trying to answer that question: class FooReference;
7
8200
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
2276
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 the class template so I know how many references I have to the body. In my case it's the Integer wrapper class which is the body. This template works for many different types. The one that I use is named Integer and is a Wrapper for an int. The...
13
2259
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 std::vector< T { public: Vec():Vec<T>() { }
1
3074
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
3719
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: #include <iostream> #include <vector> using namespace std;
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.