non-type parameter template problem

J

jjw358

i have a .h file that includes the following
template<std::size_t n>
class simplesusp {
public:
simplesusp();

};

in my .cc file, i try to say
simplesusp<8> s;

and i get the following msg from g++
undefined reference to `simplesusp<8u>::simplesusp()'

not sure what i'm doing wrong, any help would be appreciated
 
S

spongejon

i have a .h file that includes the following
template<std::size_t n>
class simplesusp {
 public:
  simplesusp();

};

in my .cc file, i try to say
simplesusp<8> s;

and i get the following msg from g++
undefined reference to `simplesusp<8u>::simplesusp()'

not sure what i'm doing wrong, any help would be appreciated

you haven't implemented
simplesusp<8u>::simplesup()

try

template<std::size_t n>
class simplesusp {
public:
simplesusp(){}
};
 
J

jjw358

sorry let me clarify:
in simplesusp.h i have
template<std::size_t n>
class simplesusp {
public:
simplesusp(){}
};

in simplesusp.cc i have

template<std::size_t n>
simplesusp<n>::simplesusp() { //something stuff }

in main.cc i have
simplesusp<8> s;

g++ gives me:
undefined reference to `simplesusp<8u>::simplesusp()'

help again appreciated. thx
 
J

jjw358

sorry let me clarify,

in simplesusp.h, i have
template<std::size_t n>
class simplesusp {
public:
simplesusp();

};

in simplesusp.cc, i have
template<std::size_t n>
simplesusp<n>::simplesusp() { // some stuff }

in main.cc, i have
simplesusp<8> s;

and i get the following msg from g++
undefined reference to `simplesusp<8u>::simplesusp()'

not sure what i'm doing wrong, any help would be appreciated
 
N

Noah Roberts

sorry let me clarify,

in simplesusp.h, i have
template<std::size_t n>
class simplesusp {
public:
simplesusp();

};

in simplesusp.cc, i have
template<std::size_t n>
simplesusp<n>::simplesusp() { // some stuff }

in main.cc, i have
simplesusp<8> s;

and i get the following msg from g++
undefined reference to `simplesusp<8u>::simplesusp()'

not sure what i'm doing wrong, any help would be appreciated

extern templates are not yet part of the standard. You therefore cannot
put template definitions in a cpp file and expect the compiler to know
you want other cpp files to have access to them. You need to put them
in headers.

http://www.parashift.com/c++-faq-lite/templates.html#faq-35.14
 
I

Ian Collins

Noah said:
extern templates are not yet part of the standard.

They are (export), but hardly anyone implements them.
You therefore cannot
put template definitions in a cpp file and expect the compiler to know
you want other cpp files to have access to them. You need to put them
in headers.

You can with some compilers which don't implement export but do have
their own rules for locating template definitions.
 
S

spongejon

Out of interest....
You mean "simplesusp();", right? Because otherwise you would be
violating the one definition rule.

Which part of the one definition rule is violated by using simplesusp()
{} ?
 

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,002
Messages
2,570,260
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top