473,396 Members | 1,917 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,396 software developers and data experts.

Using array variables as a non-type template arguments

Hi,

I need a template class taking several non-type arguments. Then I want
to be able to pass these arguments to the constructor of another non-
template class. So far I have this (I did some editing to simplify the
thing):

template<int const* rule_, double const* raw_oper_>
struct A{

static const int* rule() { return rule_; }
static const double* raw_oper() {return raw_oper_; }
};

I have the arrays defined with external linkage:

extern int const _rule[]={ 0, 1 };
extern double const _raw_oper[]={ 0.0, 1.0 };

A<_rule, _raw_opera;

struct B{

B(const int* rule, const double * raw_oper) { // create B with the
arrays };
// more stuff here
};

So far it's fine (I guess). This is pretty much the example on how to
use char const* arguments in page 110 of Vandevoorde & Josuttis book.
However if I do:

B b(a::rule(), a::raw_oper());

The compiler complains with something like:

operators.h:522: error: no matching function for call to 'B::B(const
double* (&)(), const int*)'
operators.h:366: note: candidates are: B::B(const double*, const
int*)

Why is there a difference in the way the array of int and the array of
double
are treated? How can I return the array variables to use them in other
parts of the code?

Many thanks in advance!
Nov 19 '07 #1
3 1994
iglpdc wrote:
Hi,

I need a template class taking several non-type arguments. Then I want
to be able to pass these arguments to the constructor of another non-
template class. So far I have this (I did some editing to simplify the
thing):

template<int const* rule_, double const* raw_oper_>
struct A{

static const int* rule() { return rule_; }
static const double* raw_oper() {return raw_oper_; }
};

I have the arrays defined with external linkage:

extern int const _rule[]={ 0, 1 };
extern double const _raw_oper[]={ 0.0, 1.0 };

A<_rule, _raw_opera;

struct B{

B(const int* rule, const double * raw_oper) { // create B with the
arrays };
// more stuff here
};

So far it's fine (I guess). This is pretty much the example on how to
use char const* arguments in page 110 of Vandevoorde & Josuttis book.
However if I do:

B b(a::rule(), a::raw_oper());

The compiler complains with something like:

operators.h:522: error: no matching function for call to 'B::B(const
double* (&)(), const int*)'
operators.h:366: note: candidates are: B::B(const double*, const
int*)
Setting aside the reasons for which you're doing it (I haven't
figured out the need for the 'A' template yet), it seems that
you have simply lost the parentheses after the 'raw_oper' in your
code (and you actually supplying them here).

Why is there a difference in the way the array of int and the array of
double
are treated? How can I return the array variables to use them in other
parts of the code?
You made a syntax error. Correct it and everything is going to be OK.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 20 '07 #2
LR
iglpdc wrote:
template<int const* rule_, double const* raw_oper_>
struct A{

static const int* rule() { return rule_; }
static const double* raw_oper() {return raw_oper_; }
};
extern int const _rule[]={ 0, 1 };
extern double const _raw_oper[]={ 0.0, 1.0 };
I've forgotten the rules, but AFAIR, those leading underscores might not
be good.

>
A<_rule, _raw_opera;

struct B{
B(const int* rule, const double * raw_oper) {}
};
B b(a::rule(), a::raw_oper());

Shouldn't that be something like:

typedef A<_rule, _raw_operAType;
B b(AType::rule(), AType::raw_oper());

or
B b(a.rule(), a.raw_oper());

Why is there a difference in the way the array of int and the array of
double are treated?
They are different types? Perhaps I don't understand the question.


How can I return the array variables to use them in other
parts of the code?
I don't think that you can return arrays. I think you can return
pointers to arrays, or use a std::vector of some sort and return that.
Or you can wrap your array in a struct and return that.

Nov 20 '07 #3
On 19 nov, 20:06, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
iglpdc wrote:
Hi,
I need a template class taking several non-type arguments. Then I want
to be able to pass these arguments to the constructor of another non-
template class. So far I have this (I did some editing to simplify the
thing):
template<int const* rule_, double const* raw_oper_>
struct A{
static const int* rule() { return rule_; }
static const double* raw_oper() {return raw_oper_; }
};
I have the arrays defined with external linkage:
extern int const _rule[]={ 0, 1 };
extern double const _raw_oper[]={ 0.0, 1.0 };
A<_rule, _raw_opera;
struct B{
B(const int* rule, const double * raw_oper) { // create B with the
arrays };
// more stuff here
};
So far it's fine (I guess). This is pretty much the example on how to
use char const* arguments in page 110 of Vandevoorde & Josuttis book.
However if I do:
B b(a::rule(), a::raw_oper());
The compiler complains with something like:
operators.h:522: error: no matching function for call to 'B::B(const
double* (&)(), const int*)'
operators.h:366: note: candidates are: B::B(const double*, const
int*)

Setting aside the reasons for which you're doing it (I haven't
figured out the need for the 'A' template yet), it seems that
you have simply lost the parentheses after the 'raw_oper' in your
code (and you actually supplying them here).
Why is there a difference in the way the array of int and the array of
double
are treated? How can I return the array variables to use them in other
parts of the code?

You made a syntax error. Correct it and everything is going to be OK.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
You're right! Sorry for such a mistake. I was two days with this :-).
I thought it was something related to double not being an integral
type, or some other complicated template stuff... Thanks again.
Nov 20 '07 #4

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

Similar topics

7
by: Phi | last post by:
Hi there, I've just started learning php and I hope you guys could help me with this problem. I've found a useful pice of code from a book to make a form and I would like to use it. I would like...
2
by: Jai | last post by:
hey guys, i was wondering if you could help me wit a little JS array problem, my variables are comming up "undefined", check it out for yourself... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
5
by: dam_fool_2003 | last post by:
Hai, I studied that the array size is fixed. But I come across a word called "variable length array". Is it possible to change the array size? So I tried the following: #include<stdio.h>...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
3
by: lovecreatesbeauty | last post by:
It is strange. Happen to get following the fragment compiled successfully. Is there anything wrong with my compiler or my mind? Please guide me to correct my understanding on it. Sincerely, ...
6
by: arnuld | last post by:
this one was much easier and works fine. as usual, i put code here for any further comments/views/advice: --------- PROGRAMME ------------ /* Stroustrup: 5.9 exercise 7 STATEMENTS: Define a...
0
by: blainegray | last post by:
Greetings This is one of those Access is not closing Excel problems. The first time through the code works fine. The second time there is a problem. After lots of combinations, I finally...
6
by: Spiro Trikaliotis | last post by:
Hello, in a project, I stumbled upon code like follows (incomplete): #if defined(MINIXVMD) || defined(MINIX_SUPPORT) || defined(__VBCC__) || (defined(__BEOS__) && defined(WORDS_BIGENDIAN)) ||...
3
by: powerej | last post by:
im having trouble printing an array with duplicate characters, i can enter and print with single characters but when i try and enter and print duplicate ones it puts blanks in my output for a sorted...
4
by: amun25dringer11 | last post by:
I hear people talking about like: const float PI=3.14; that and they say you can only change it in one place but why do you need it if you can use it in a variable ex. float PI=3.14; and then...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
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...
0
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...
0
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...
0
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,...

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.