template export question

N

New_user

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/minor/win95+/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?
 
S

Sumit Rajan

New_user said:
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/minor/win95+/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?
 
D

Denis Remezov

New_user said:
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/minor/win95+/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
 
N

New_user

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top