could you explain the code from the second header file?

4

466

/// headerfile; definition file for BBB class
template <class CORE>
class BBB : public CORE {};




/// another header file
class AAA;
template <class AAA> class BBB;
typedef BBB<AAA> CCC;
 
A

Alf P. Steinbach

* 466:
/// headerfile; definition file for BBB class
template <class CORE>
class BBB : public CORE {};

This is the code you don't want explained.

/// another header file
class AAA;
template <class AAA> class BBB;
typedef BBB<AAA> CCC;

Assuming the header file also contains a definition of template class
BBB, this defines a class CCC.

It may be that it's done this way in order to define an extern linkage
variable or constant in the header file.
 
4

466

Alf said:
* 466:

This is the code you don't want explained.



Assuming the header file also contains a definition of template class
BBB, this defines a class CCC.

It may be that it's done this way in order to define an extern linkage
variable or constant in the header file.


CCC is not a type?
 
4

466

466 said:
CCC is not a type?

I think because of this definition I have undefined references to BBB
class members ...
- undefined reference to BBB<AAA>::some method()

is it possible?
 
4

466

466 said:
I think because of this definition I have undefined references to BBB
class members ...
- undefined reference to BBB<AAA>::some method()

is it possible?


the second header file does not include any header or define BBB ...
 
V

VJ

466 said:
I think because of this definition I have undefined references to BBB
class members ...
- undefined reference to BBB<AAA>::some method()

is it possible?

No. When you do
CCC::some_method()
is the same as you do
BBB<AAA>::some_method()

assuming some_method() is a static function in BBB<AAA>
 
4

466

VJ said:
No. When you do
CCC::some_method()
is the same as you do
BBB<AAA>::some_method()

assuming some_method() is a static function in BBB<AAA>

can you tell me why do we need a static method?
it's not so evident ... or is it?

thanx
Stefan
 
V

VJ

466 said:
VJ wrote:




can you tell me why do we need a static method?
it's not so evident ... or is it?

thanx
Stefan

class a
{
public:
static void foo()
{ }
}


If it is a static method, you can call it like this:
a::foo()

If it is not a static method, you have to create an object of that
class, and then can call the function:
a obj;
a.foo();


I did not say you do need a static method - it all depends what your
class has to do
 
V

VJ

VJ said:
If it is not a static method, you have to create an object of that
class, and then can call the function:
a obj;
a.foo();

Sorry this is a type. Should be:

a obj;
obj.foo();
 
4

466

thanx a lot for your help.
found the problem for undefined references: the template class was
defined in a header file and the definition was in a separate source
file ... so the linker tries to link symbols that does not exist,
because the gcc compiler does not generate code for that source file
....

Stefan
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top