Template class object creation problem

S

shyam

Hi All

I have a generic template class called StubController

I also wrote a main ( ) function to instantiate the class and test it

I instantiated it like
StubController<int> stubber;

The problem is that when I try to instantiate the class within another
class's function or in the global scope of another class source file
then I get an error like
undefined reference to `StubController<int>::StubController[in-charge]
()'

In this case I have to instantiate as
StubController<int> stubber( );

What is the difference between StubController<int> stubber; &
StubController<int> stubber( )? Am I doing any obvious mistake ?

Plz help

Thanks in advance
Shyam
 
J

James Kanze

I have a generic template class called StubController
I also wrote a main ( ) function to instantiate the class and
test it
I instantiated it like
StubController<int> stubber;
The problem is that when I try to instantiate the class within
another class's function or in the global scope of another
class source file then I get an error like undefined reference
to `StubController<int>::StubController[in-charge] ()'

It sounds like you've declared a constructor but haven't
provided an implementation of it. (With most compilers, the
implementation must be in the header.)
In this case I have to instantiate as
StubController<int> stubber( );

That doesn't instantiation anything, since it is just a
declaration (of a function taking no arguments, and returning a
StubController said:
What is the difference between StubController<int> stubber; &
StubController<int> stubber( )? Am I doing any obvious mistake ?

The first defines a variable, the second declares a function.

It's hard to say without more source, but two possibilities come
to mind: either you've declared a default constructor, but
haven't defined it, or you've declared a default constructor,
but defined it in source file which doesn't instantiate it.
 

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
474,159
Messages
2,570,881
Members
47,418
Latest member
NoellaXku

Latest Threads

Top