Hi!
This program:
template<class T_index, class T_data>
class AAA
{
public:
AAA(int ii = 0,int jj = 0) {}
};
AAA<int, inta1(10, 20); // this works
AAA<int, inta3(10, 20); // this works
class BBB
{
AAA<int, inta4; // this works
AAA<int, inta5(10, 20); // this doesn't work
};
int main()
{
return 0;
}
fails to compile, I tried
g++296 and g++32 give errors:
test.cpp:17: invalid data member initiailization
test.cpp:17: use `=' to initialize static data members
g++34 g++4 give errors:
test.cpp:17: error: expected identifier before numeric constant
test.cpp:17: error: expected `,' or `...' before numeric constant
test.cpp:17: error: ISO C++ forbids declaration of `parameter' with no
type
I tried to play with typename keyword with no success.
I wonder what Bjarne Stroustrup is going to say about this mess.
Any ideas?
Reinis 2 1929
reinisr wrote:
Hi!
This program:
template<class T_index, class T_data>
class AAA
{
public:
AAA(int ii = 0,int jj = 0) {}
};
AAA<int, inta1(10, 20); // this works
AAA<int, inta3(10, 20); // this works
class BBB
{
AAA<int, inta4; // this works
This is a declaration.
AAA<int, inta5(10, 20); // this doesn't work
Here you are trying to define (initialize) a member object, you are not
supposed to do that inside the class body. You need to do this inside
BBB constructor.
dragoncoder wrote:
reinisr wrote:
>Hi!
This program:
template<class T_index, class T_data> class AAA { public: AAA(int ii = 0,int jj = 0) {} };
AAA<int, inta1(10, 20); // this works AAA<int, inta3(10, 20); // this works
class BBB { AAA<int, inta4; // this works
This is a declaration.
> AAA<int, inta5(10, 20); // this doesn't work
Here you are trying to define (initialize) a member object, you are not
supposed to do that inside the class body. You need to do this inside
BBB constructor.
To be more precise, the compiler-generated default constructor for BBB
default constructs a4. a5 is a syntax error.
To do what you want:
class BBB
{
AAA<int, inta4;
AAA<int, inta5;
public:
BBB() : a4(), a5(10, 20) { }
}; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tjerk Wolterink |
last post by:
I've xml code like this:
roles.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<roles xmlns="http://www.wolterinkwebdesign.com/xml/roles">
<!--
! The admin role.
! And admin should have...
|
by: Dave |
last post by:
Hello all,
Here is the definition I'm using of a static const class member:
template<typename T, typename U>
const U directed_graph_t<T, U>::INFINITY =
(
std::numeric_limits<U>::has_infinity...
|
by: grundmann |
last post by:
Hello,
i got a strange compiler error.
When compiling the following:
// forward declarations
typedef AvlTree<LineSegment,LineSegmentComperator> LSTree;
void handleEventPoint (const...
|
by: sleepydj |
last post by:
Hello,
I have a simple program to create strings from the corresponding
double/integer values. For any data type similar to int, I have a
template set up in a file misc.h:
...
|
by: Robbie Hatley |
last post by:
I'd always thougth that a C++ compiler/linker should be able to
instantiate a template in mulitple places (say, in two different
translation units), even using the same template parameters so
that...
|
by: stromhau |
last post by:
Ok, i have a file with main and an additional .cpp file i include in the main file but i get a lot of strange warnings when including. Both files compile just great separately. It seems that it have...
|
by: =?gb2312?B?tdjH8reitq+7+g==?= |
last post by:
Who can tell me the result in your compiler? Is it a bug or standard
beheiver?
class A
{
template<int>
void a();
};
class B:A
|
by: creativeinspiration |
last post by:
Hey Everybody. I have a question. I have a code like this in my .cpp file of the class:
template <typename T>
int myClass<T>::getNumber()
{
return 1;
}
In my .h file I have everything...
|
by: Zheng Da |
last post by:
Hello,
I want a use the class of map in a class with template,
and the type of elements in map is specified by the parameter of the
class's template.
For example,
template <typename key,...
|
by: jdmuys |
last post by:
Hi,
I have a strange bug in my code, which I managed to reduce to the tiny
C++ program below.
The compiler reject the "class1<Type>::insideStruct *p2;" declaration
with the following error...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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,...
|
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...
|
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,...
| |