Dear All,
Assume I have a class template:
template<class T, int N = 0>
class A
{
void fun1();
void fun2();
void fun3();
void fun4();
void NRelatedFun(); // related to template parameter N.
};
Here fun1(), fun2(), fun3(), fun4() are the same. NRelatedFun() are
related to N. How to code the particular functions? I think class
template can be partial specialized. So I write as
template<class T, 1>
void A<T,1>::NRelate dFun();
But the compilor give some errors. I tried several other ways, but
still failed.
I appreicate your kind help.
Shuisheng 2 1682
shuisheng wrote:
Assume I have a class template:
template<class T, int N = 0>
class A
{
void fun1();
void fun2();
void fun3();
void fun4();
void NRelatedFun(); // related to template parameter N.
};
Here fun1(), fun2(), fun3(), fun4() are the same. NRelatedFun() are
related to N. How to code the particular functions? I think class
template can be partial specialized. So I write as
template<class T, 1>
void A<T,1>::NRelate dFun();
But the compilor give some errors. I tried several other ways, but
still failed.
First of all, what errors does your compiler give you? Please
start every posting attempt with reading the FAQ. Here, 5.8 is
applicable.
Second, you're specialising a member without specialising the class.
It could be the problem. Why are you declaring a member of your
A<T,1as a function when the template specialisation can have it
as a static data member? YOu need to specialise the class first,
then show that 'NRelatedFun' is indeed a function with the specific
signature, then you can define it.
Anyway, read the FAQ 5.8.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor Bazarov 写道:
shuisheng wrote:
Assume I have a class template:
template<class T, int N = 0>
class A
{
void fun1();
void fun2();
void fun3();
void fun4();
void NRelatedFun(); // related to template parameter N.
};
Here fun1(), fun2(), fun3(), fun4() are the same. NRelatedFun() are
related to N. How to code the particular functions? I think class
template can be partial specialized. So I write as
template<class T, 1>
void A<T,1>::NRelate dFun();
But the compilor give some errors. I tried several other ways, but
still failed.
First of all, what errors does your compiler give you? Please
start every posting attempt with reading the FAQ. Here, 5.8 is
applicable.
I got your message. I have read it and will follow it.
>
Second, you're specialising a member without specialising the class.
It could be the problem. Why are you declaring a member of your
A<T,1as a function when the template specialisation can have it
as a static data member? YOu need to specialise the class first,
then show that 'NRelatedFun' is indeed a function with the specific
signature, then you can define it.
Thanks!.
Shuisheng This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paul MG |
last post by:
Hi
Template partial specialization always seems like a fairly
straightforward concept - until I try to do it :).
I am trying to implement the input sequence type (from Stroustrup
section 18.3.1, 'Iseq'). I want the version for containers that he
gives, but also to provide a specialization for construction from a
pair<It,It> (eg because that is returned by equal_range()).
|
by: TT \(Tom Tempelaere\) |
last post by:
Comeau compiler complains (too few arguments for class template "B") at line
***
#include <memory>
template<typename T, size_t n>
struct A {};
template<typename T, size_t n>
struct B;
|
by: Walt Karas |
last post by:
The following gives an error in the declaration of the
member function x() of the class template Tpl, compiliing
with a recent version of GCC under Solaris:
class A { };
class B { };
template <typename Base>
class Tpl : protected Base
{
|
by: BekTek |
last post by:
I'm still confused about the template partial specialization which is used
in many libraries..
due to lack of introduction for beginner..
Could you tell me about that in short?
Thanks in advance..
|
by: Levent |
last post by:
Hi,
Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1):
#include <iostream>
template<class T, unsigned N>
struct Foo {
void func();
};
template<class T, unsigned N>
| |
by: Alfonso Morra |
last post by:
Does VC 7.1 support template specialization and partial specialization ?
|
by: wkaras |
last post by:
I tried a couple of compilers, and both gave errors compiling this:
template <bool fin, typename T>
T foo(T val);
template <typename T>
T foo<true, T>(T val) { return(val); }
But both gave no errors compiling this:
|
by: Marek Vondrak |
last post by:
Hello.
I have written the following program and am curious why it prints "1" "2".
What are the exact effects of explicitly providing function template
parameters at the call? Is the second assign() function really a
specialization of the first assign() or is it an assign() overload?
Thank you.
-- Marek
|
by: aaragon |
last post by:
Hi everyone,
The idea is quite simple: generate a container with random values in
it. For that, I decided to create a class that I called
RandomContainer that inherits from a container (with default value
std::vector<T>). To handle the different ways that the values are
randomized, I created a traits class. The problem that I have, is that
the function randomize() within the traits class takes different
parameters depending on the type...
|
by: jason.cipriani |
last post by:
I never seem to be able to get this right. Here I have some code:
template <typename T, int Nclass A {
void f (T);
};
template <typename Tvoid A<T,1>::f (T) {
}
template <typename Tvoid A<T,3>::f (T) {
|
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets 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: 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...
|
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 projectplanning, coding, testing, and deploymentwithout 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: 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...
| |
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |