471,584 Members | 1,565 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,584 software developers and data experts.

template export question

Hello.

Excerpt from ISO/IEC 14882 :
14/6
A namespace-scope declaration or definition of ........skipped...... a non-
inline member function of a class template or a static data member of a class
template may be preceded by the export keyword.

and from http://www.comeaucomputing.com/4.3.0...5+/43stuff.txt :
A template must be declared export at both the point of definition and
the point of reference.

I have some files:

//templ.h
template<class T>
class A
{
public:
void fun();
static int i_;
};
//I want to export A<T>::fun and A<T>::i_, but I do not want to declare class
//A as exported

//def.cpp
//1!
//exported definitions are here, ordering problems?
//fun first declared as non-exported and later as exported?

export template<class T>
void A<T>::fun()
{
}

export template<class T>
int A<T>::i_ = 0;

//user.cpp
//2! here's class usage

#include "templ.h"

int main()
{
A<int>a;
a.fun();
}

How can I declare A<T>::fun in user.cpp as exported at the point of reference?
Jul 22 '05 #1
10 1823

"New_user" <tp*****@mail.ru> wrote in message
news:d2*************************@posting.google.co m...
Hello.

Excerpt from ISO/IEC 14882 :
14/6
A namespace-scope declaration or definition of ........skipped...... a non- inline member function of a class template or a static data member of a class template may be preceded by the export keyword.

and from http://www.comeaucomputing.com/4.3.0...5+/43stuff.txt :
A template must be declared export at both the point of definition and
the point of reference.

I have some files:

//templ.h
template<class T>
class A
{
public:
void fun();
static int i_;
};
//I want to export A<T>::fun and A<T>::i_, but I do not want to declare class //A as exported
The effect would be exactly the same if you do this:

//templ.h
export template <class T>
class A {
public:
void fun();
static int i_;
};
"export" in def.cpp is then redundant.

//def.cpp

#include "templ.h"

template<class T>
void A<T>::fun()
{}

template<class T>
int A<T>::i_ = 0;

Regards,
Sumit.

//def.cpp
//1!
//exported definitions are here, ordering problems?
//fun first declared as non-exported and later as exported?

export template<class T>
void A<T>::fun()
{
}

export template<class T>
int A<T>::i_ = 0;

//user.cpp
//2! here's class usage

#include "templ.h"

int main()
{
A<int>a;
a.fun();
}

How can I declare A<T>::fun in user.cpp as exported at the point of

reference?
Jul 22 '05 #2

"New_user" <tp*****@mail.ru> wrote in message
news:d2*************************@posting.google.co m...
Hello.

Excerpt from ISO/IEC 14882 :
14/6
A namespace-scope declaration or definition of ........skipped...... a non- inline member function of a class template or a static data member of a class template may be preceded by the export keyword.

and from http://www.comeaucomputing.com/4.3.0...5+/43stuff.txt :
A template must be declared export at both the point of definition and
the point of reference.

I have some files:

//templ.h
template<class T>
class A
{
public:
void fun();
static int i_;
};
//I want to export A<T>::fun and A<T>::i_, but I do not want to declare class //A as exported
The effect would be exactly the same if you do this:

//templ.h
export template <class T>
class A {
public:
void fun();
static int i_;
};
"export" in def.cpp is then redundant.

//def.cpp

#include "templ.h"

template<class T>
void A<T>::fun()
{}

template<class T>
int A<T>::i_ = 0;

Regards,
Sumit.

//def.cpp
//1!
//exported definitions are here, ordering problems?
//fun first declared as non-exported and later as exported?

export template<class T>
void A<T>::fun()
{
}

export template<class T>
int A<T>::i_ = 0;

//user.cpp
//2! here's class usage

#include "templ.h"

int main()
{
A<int>a;
a.fun();
}

How can I declare A<T>::fun in user.cpp as exported at the point of

reference?
Jul 22 '05 #3

"Sumit Rajan" <su********@myrealbox.com> wrote in message
news:c5*************@ID-206022.news.uni-berlin.de...

"New_user" <tp*****@mail.ru> wrote in message
news:d2*************************@posting.google.co m...

How can I declare A<T>::fun in user.cpp as exported at the point of

reference?

Sorry. Please disregard that post. I missed that question when I read
through your message. :-)
Jul 22 '05 #4

"Sumit Rajan" <su********@myrealbox.com> wrote in message
news:c5*************@ID-206022.news.uni-berlin.de...

"New_user" <tp*****@mail.ru> wrote in message
news:d2*************************@posting.google.co m...

How can I declare A<T>::fun in user.cpp as exported at the point of

reference?

Sorry. Please disregard that post. I missed that question when I read
through your message. :-)
Jul 22 '05 #5

"Sumit Rajan" <su********@myrealbox.com> wrote in message
news:c5*************@ID-206022.news.uni-berlin.de...

"New_user" <tp*****@mail.ru> wrote in message
news:d2*************************@posting.google.co m...

How can I declare A<T>::fun in user.cpp as exported at the point of

reference?

Sorry. Please disregard that post. I missed that question when I read
through your message. :-)

Jul 22 '05 #6

"Sumit Rajan" <su********@myrealbox.com> wrote in message
news:c5*************@ID-206022.news.uni-berlin.de...

"New_user" <tp*****@mail.ru> wrote in message
news:d2*************************@posting.google.co m...

How can I declare A<T>::fun in user.cpp as exported at the point of

reference?

Sorry. Please disregard that post. I missed that question when I read
through your message. :-)

Jul 22 '05 #7
New_user wrote:

Hello.

Excerpt from ISO/IEC 14882 :
14/6
A namespace-scope declaration or definition of ........skipped...... a non-
inline member function of a class template or a static data member of a class
template may be preceded by the export keyword.

and from http://www.comeaucomputing.com/4.3.0...5+/43stuff.txt :
A template must be declared export at both the point of definition and
the point of reference.
[snip]
How can I declare A<T>::fun in user.cpp as exported at the point of reference?


If I understand you correctly you don't want to declare your templates with the
export keyword at the point you are using them and still want them to be resolved
as exported? If so, I would guess that would not do. I take 14/6 and 14/8 to mean
that the first declaration of exported templates in /each/ of the translation units
must use the export keyword; subsequent redeclarations or definitions do not need to
use "export"; one and only one of the translation units must provide a definition.

I am not quite sure and would like to confirm if the above is correct, for myself.

It may sound ugly, but if you don't want to go the inclusion way I'd consider
explicit instantiation.

Denis
Jul 22 '05 #8
New_user wrote:

Hello.

Excerpt from ISO/IEC 14882 :
14/6
A namespace-scope declaration or definition of ........skipped...... a non-
inline member function of a class template or a static data member of a class
template may be preceded by the export keyword.

and from http://www.comeaucomputing.com/4.3.0...5+/43stuff.txt :
A template must be declared export at both the point of definition and
the point of reference.
[snip]
How can I declare A<T>::fun in user.cpp as exported at the point of reference?


If I understand you correctly you don't want to declare your templates with the
export keyword at the point you are using them and still want them to be resolved
as exported? If so, I would guess that would not do. I take 14/6 and 14/8 to mean
that the first declaration of exported templates in /each/ of the translation units
must use the export keyword; subsequent redeclarations or definitions do not need to
use "export"; one and only one of the translation units must provide a definition.

I am not quite sure and would like to confirm if the above is correct, for myself.

It may sound ugly, but if you don't want to go the inclusion way I'd consider
explicit instantiation.

Denis
Jul 22 '05 #9
Hello, Denis.
If I understand you correctly you don't want to declare your templates with the
export keyword at the point you are using them and still want them to be resolved
as exported?


No. I just want to understand, how can I declare a non-inline
member-function of a class template (not a member template) or how can
I declare a static data-member of a class template as exported? It
seems to me, the only way is to declare class as exported. But
Standard says, that declaration of a non-inline member-function (or
static data-member) can be preceeded by the 'export' keyword.
Jul 22 '05 #10
Hello, Denis.
If I understand you correctly you don't want to declare your templates with the
export keyword at the point you are using them and still want them to be resolved
as exported?


No. I just want to understand, how can I declare a non-inline
member-function of a class template (not a member template) or how can
I declare a static data-member of a class template as exported? It
seems to me, the only way is to declare class as exported. But
Standard says, that declaration of a non-inline member-function (or
static data-member) can be preceeded by the 'export' keyword.
Jul 22 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by LaBird | last post: by
10 posts views Thread by New_user | last post: by
15 posts views Thread by iuweriur | last post: by
8 posts views Thread by Tim Frink | last post: by
reply views Thread by leo001 | last post: by

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.