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>::Collect ion' : missing storage-class
or type specifiers
foo.cpp(48) : error C2065: 'T' : undeclared identifier
foo.cpp(48) : error C2955: 'foo' : use of class template requires
template argument list
Hope you guys can help me...
foo.h
--------------------------------------
template <class T>
class foo
{
public:
typedef std::vector< foo<T> > Collection;
foo();
virtual ~foo(void);
Collection& getCollection() ;
private:
Collection col;
};
foo.cpp
--------------------------------------
template <class T>
foo<T>::foo(voi d)
{
}
template <class T>
foo<T>::~foo(vo id)
{
}
template <class T>
foo<T>::Collect ion& foo<T>::getColl ection()
{
return col;
}; 5 1826
* kr*******@gmail .com: Hi
Does some of you know how to declare getCollection() in the cpp file?
2 don'ts:
* Technically, only one compiler supports placing template definitions
in a separately compiled cpp file.
* Stylistically, if you use the name 'getCollection' instead of just
'collection', your code will be less readable, and in other cases
than the one you have you will have removed a useful name for an
optimized command-oriented version of an expression-oriented func.
My code snippet below produces following compile error:
foo.cpp(48) : error C2143: syntax error : missing ';' before '&' foo.cpp(48) : error C2501: foo<T>::Collect ion' : missing storage-class or type specifiers foo.cpp(48) : error C2065: 'T' : undeclared identifier foo.cpp(48) : error C2955: 'foo' : use of class template requires template argument list
Hope you guys can help me...
foo.h --------------------------------------
Here you need
#ifndef FOO_H
#define FOO_H
#include <vector>
template <class T> class foo { public: typedef std::vector< foo<T> > Collection;
Are you aware that you're defining a tree structure? Each foo
contains a possibly non-empty collection of foo's. foo(); virtual ~foo(void);
'void' is a C-ism: don't. Collection& getCollection() ;
Should probably also have a 'const' version of that function. private: Collection col; };
#endif
foo.cpp
See above -- with most compilers you simply can't place these
definitons in a separately compiled cpp file: put them in the
header file.
template <class T> foo<T>::foo(voi d) { }
template <class T> foo<T>::~foo(vo id) { }
template <class T> foo<T>::Collect ion& foo<T>::getColl ection()
Here you need a 'typename' to tell the compiler that Collection is a type:
typename foo<T>::Collect ion& foo<T>::getColl ection()
{ return col; };
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
>Are you aware that you're defining a tree structure? Each foo contains a possibly non-empty collection of foo's.
Yes, I'm aware of that.
Technically, only one compiler supports placing template definitions in a separately compiled cpp file.
I'm using MSVC 7.1, and it seems that it is supported here. Does GCC
not support that?
Thanks a lot for your quick answer.
- Dennis
* krema2ren: Are you aware that you're defining a tree structure? Each foo contains a possibly non-empty collection of foo's.
Yes, I'm aware of that.
Technically, only one compiler supports placing template definitions in a separately compiled cpp file.
I'm using MSVC 7.1, and it seems that it is supported here. Does GCC not support that?
Neither MSVC 7.1 nor GCC support that, yet.
It will compile but won't link.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
>Neither MSVC 7.1 nor GCC support that, yet. It will compile but won't link.
Unfortunately you are right....
- Dennis This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Me |
last post by:
I am not understanding an aspect of how to implement a class template in a
..cpp file.
What I do know is that there are at least two problems with my understanding
of how to accomplish the definition of a template outside the class. One
problem is how to refer to a typedef that is a member of the classe's public
interface in the .cpp file. The second problem is that if I modify my code
to use the template variables and not my typedefs,...
|
by: John Harrison |
last post by:
The following code does not compile
template <class Derived>
struct X
{
typedef typename Derived::type type;
};
struct Y : public X<Y>
{
|
by: G Patel |
last post by:
Pg. 140 of K&R2 shows an example of mutually referential structure
declarations...
struct t
{
struct s *p;
};
struct s
{
|
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>() { }
|
by: Grizlyk |
last post by:
Hello.
Why were base class "typedefs" hidden by template<and explicit usage
of them does not work too?
Try open only one of the lines in the example below
//using Tparent::Tptr;
//typedef Tparent::Tptr Tptr;
Consider example:
| |
by: toton |
last post by:
Hi,
I want to specialize template member function of a template class .
It is creating some syntax problem ....
Can anyone say how to do it ?
The class is something like this
template<typename T,typename Alloc = std::allocator<T
class CircularBuffer4 {
public:
typedef typename CircularBuffer<T,Alloc>::size_type
|
by: Paul J. Lucas |
last post by:
Given:
template<typename T,typename Uclass C { };
template<typename Ttypedef C<T,intC2;
I get:
test.cpp:2: error: template declaration of 'typedef'
Are template typedefs still not supported in g++ 4.1.2?
|
by: 2b|!2b==? |
last post by:
I have the ff template class:
template <class T1, class T2class Periodic ;
I have two questions/problems
Q1).
I want to specialize it further into two template classes:
|
by: Bob Nelson |
last post by:
After completing KNK2, my interest in C was reignited, prompting a
re-reading of Traister's dubious book on pointers. Then I dusted off
the fine ``C Traps and Pitfalls'' by Andy Koenig. Nowadays I primarily
work in PHP, Perl and C++. Consequently my C skills have atrophied.
So inspired by CT&P's ``calendar'' example on page 30, I decided to
brush up on some elementary C (although Koenig describes it as walking
``out on the ice'') with...
|
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...
|
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,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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
| |
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...
| |