473,587 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using a template in a vector - getting error C2955

Gil
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;
public :
AnyValue(T inv)
{
val = inv;
}
};

class ValuesObject {
int count;
vector<AnyValue , allocator<AnyVa lue> > ivo; // error occurs here!!
public :
ValuesObject() {}
~ValuesObject() {}
int getCount()
{
return count;
}
void addValue(AnyVal ue av)
{
vector<AnyValue , allocator<AnyVa lue> >::iterator iter = ivo.end();
ivo.insert(iter , av);
}
};

I'm getting :

error C2955: 'AnyValue' : use of class template requires template
argument list

Can anyone see what I am doing wrong?

As far as C++ is concerned, is what I am doing correct? Is this a
compiler issue with Visual C++?
Jul 22 '05 #1
7 8188

"Gil" <br************ **@hotmail.com> wrote in message
news:ad******** *************** ***@posting.goo gle.com...
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;
public :
AnyValue(T inv)
{
val = inv;
}
};

class ValuesObject {
int count;
vector<AnyValue , allocator<AnyVa lue> > ivo; // error occurs here!!
public :
ValuesObject() {}
~ValuesObject() {}
int getCount()
{
return count;
}
void addValue(AnyVal ue av)
{
vector<AnyValue , allocator<AnyVa lue> >::iterator iter = ivo.end();
ivo.insert(iter , av);
}
};

I'm getting :

error C2955: 'AnyValue' : use of class template requires template
argument list


AnyValue is a class template and NOT a concrete class.
Vector is also a class template and to make a concrete class out of it you need
to provide a
template parameter (some built-in type/concrete class).
Since Vector does not expect a template template parameter, AnyValue is
rejected by it.
Hence you can't pass it as an argument to vector.

Best wishes,
Sharad
Jul 22 '05 #2
"Gil" <br************ **@hotmail.com> wrote:
#include <vector>

using namespace std;

template <typename T>
class AnyValue {
T val;
public :
AnyValue(T inv)
{
val = inv;
}
};
A small aside - better to say:

AnyValue(T inv) : val(inv)
{
}

This will cause val to just be constructed, instead of being default
constructed and then assigned the value of inv. Even better, say:

AnyValue(const T &inv) : val(inv)

This will prevent an unnecessary copy when the constructor is called.
class ValuesObject {
int count;
vector<AnyValue , allocator<AnyVa lue> > ivo; // error occurs here!!


You have defined AnyValue as a template class, so it needs a template
argument (eg. AnyValue<int>).

It looks like you might mean:

template <typename T>
class ValuesObject
{
vector<AnyValue <T> > ivo;
...
};

Hope this is helpful,

David F
Jul 22 '05 #3
"Gil" <br************ **@hotmail.com> wrote in message
news:ad******** *************** ***@posting.goo gle.com...
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;
public :
AnyValue(T inv)
{
val = inv;
}
};

class ValuesObject {
int count;
vector<AnyValue , allocator<AnyVa lue> > ivo; // error occurs here!!
public :
ValuesObject() {}
~ValuesObject() {}
int getCount()
{
return count;
}
void addValue(AnyVal ue av)
{
vector<AnyValue , allocator<AnyVa lue> >::iterator iter = ivo.end();
ivo.insert(iter , av);
}
};

I'm getting :

error C2955: 'AnyValue' : use of class template requires template
argument list

Can anyone see what I am doing wrong?

As far as C++ is concerned, is what I am doing correct? Is this a
compiler issue with Visual C++?


You have defined AnyValue as a template class but you have not provided the
template arguments.
All you have to do is to replace "AnyValue" in class ValuesObject something
like "AnyValue<int>" .
Else if you do not want a concrete type like int make ValuesObject class
also as a template class and provide the
template argument for AnyValue.See the code below.That compiles without any
error in the Visual C++ 6.

#include <vector>

using namespace std;

template <typename T>
class AnyValue {
T val;
public :
AnyValue(T inv )
{
val = inv;
}
};

template <typename U> class ValuesObject {
int count;
vector<AnyValue <U>, allocator<AnyVa lue<U> > > ivo;
public :
ValuesObject() {}
~ValuesObject() {}
int getCount()
{
return count;
}
void addValue(AnyVal ue<U> av)
{
vector<AnyValue <U>, allocator<AnyVa lue<U> > >::iterator iter =
ivo.end();
ivo.insert(iter , av);
}
};

Jul 22 '05 #4

"Sharad Kala" <no************ *****@yahoo.com > wrote in message
news:bu******** ****@ID-221354.news.uni-berlin.de...
[SNIP] AnyValue is a class template and NOT a concrete class.
Vector is also a class template and to make a concrete class out of it you need to provide a
template parameter (some built-in type/concrete class).
Since Vector does not expect a template template parameter, AnyValue is
rejected by it.
Hence you can't pass it as an argument to vector.

Best wishes,
Sharad


Just to elaborate on how to do it right you need to supply a template
argument. For example:

vector< AnyValue<int> > MyVec; // note the blank between the two greater
signs!

HTH
Chris
Jul 22 '05 #5

"Chris Theis" <Ch************ *@nospam.cern.c h> wrote in message
news:bu******** **@sunnews.cern .ch...

"Sharad Kala" <no************ *****@yahoo.com > wrote in message
news:bu******** ****@ID-221354.news.uni-berlin.de...

[SNIP]
AnyValue is a class template and NOT a concrete class.
Vector is also a class template and to make a concrete class out of it you

need
to provide a
template parameter (some built-in type/concrete class).
Since Vector does not expect a template template parameter, AnyValue is
rejected by it.
Hence you can't pass it as an argument to vector.

Best wishes,
Sharad


Just to elaborate on how to do it right you need to supply a template
argument. For example:

vector< AnyValue<int> > MyVec; // note the blank between the two greater
signs!


Let me also elaborate again :-)
You need the space between the two greater-than signs because of a compiler
property called as "Maximal Munch" i.e.
consume as many tokens as possible. When compiler sees the two >> signs it
interprets it as the shift operator hence the need for the
space as Chris pointed out.

Best wishes,
Sharad
Jul 22 '05 #6

"Sharad Kala" <no************ *****@yahoo.com > wrote in message
news:bu******** ****@ID-221354.news.uni-berlin.de...

"Chris Theis" <Ch************ *@nospam.cern.c h> wrote in message
news:bu******** **@sunnews.cern .ch...
[SNIP] Let me also elaborate again :-)
You need the space between the two greater-than signs because of a compiler property called as "Maximal Munch" i.e.
consume as many tokens as possible. When compiler sees the two >> signs it
interprets it as the shift operator hence the need for the
space as Chris pointed out.

Best wishes,
Sharad


BTW there is talk that future compilers will parse such a statement
correctly even with the blank missing. Though, todays compilers will
certainly have a problem with this.

Cheers
Chris
Jul 22 '05 #7

"Chris Theis" <Ch************ *@nospam.cern.c h> wrote in message
news:bu******** **@sunnews.cern .ch...

"Sharad Kala" <no************ *****@yahoo.com > wrote in message
news:bu******** ****@ID-221354.news.uni-berlin.de...

"Chris Theis" <Ch************ *@nospam.cern.c h> wrote in message
news:bu******** **@sunnews.cern .ch...

[SNIP]
Let me also elaborate again :-)
You need the space between the two greater-than signs because of a

compiler
property called as "Maximal Munch" i.e.
consume as many tokens as possible. When compiler sees the two >> signs it
interprets it as the shift operator hence the need for the
space as Chris pointed out.

Best wishes,
Sharad


BTW there is talk that future compilers will parse such a statement
correctly even with the blank missing. Though, todays compilers will
certainly have a problem with this.


Absolutely true :-)
In fact I read that C++ Standard Committee will take care of it in the next
revision of the standard.

Best wishes,
Sharad
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2364
by: Allan Bruce | last post by:
I have had a look through the FAQ and found that if I am using a class template then I need an argument list. I have tried to add this but it is not quite working - i.e. it doesnt compile. My code is below, could somebody please point me in the right direction? Thanks Allan #include <iostream>
5
5703
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ================================================================= Error 19: "CORBAManagerMessages.h", line 4 # Unexpected 'std'. using std::string; ^^^
6
2123
by: bluekite2000 | last post by:
I have Vector<complex<float> > V(5); V.rand(); Vector<float> V1(V); //specialized function here to return norm(V). This works fine Vector<double> V2(5); V2.rand(); Vector<float> V3(V2);//error no matching function for call to norm(double)
5
1241
by: rich | last post by:
Hi there, I defined a class template (MyClass) and some member variables and functions, as following: template<class T1, class T2> class MyClass { ... struct m_variable
5
1814
by: krema2ren | last post by:
Hi Does some of you know how to declare getCollection() in the cpp file? My code snippet below produces following compile error: foo.cpp(48) : error C2143: syntax error : missing ';' before '&' foo.cpp(48) : error C2501: foo<T>::Collection' : missing storage-class or type specifiers foo.cpp(48) : error C2065: 'T' : undeclared identifier...
5
1898
by: Pedro Sousa | last post by:
Hi, I'm trying to create an template class that represent points in all possible dimensions, what I've made until now is #ifndef _POINT_HPP_ #define _POINT_HPP_ #include <vector>
1
3067
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>
1
3196
by: =?UTF-8?B?SmVucyBNw7xsbGVy?= | last post by:
(I also posted this to boost-user) The BGL implementation of breadth-first search uses a dedicated color map. I had the following idea: Some algorithms don't need to distinguish black/gray, but have an unused value in e.g. a distance map, e.g. -1, to which the map can be initialised. So I tried to write a map adapter which can be passed...
4
3133
by: Jim Langston | last post by:
This should illistrate what I am trying to do: template <class T> T SomeFunction( T parm ) { return parm; } template <class T> class SomeClass
0
7915
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...
0
7843
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...
0
8205
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. ...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
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...
0
3840
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...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.