Templates - Garbage In Garbage Not Out

R

ramiro_b

All,

In a .h file, I am declaring/defining a template as

template<class T> class MyClass
{
public:
void test()
{
haskdfhsjfksfhkfskfsfkklkll89829482498020
gdgk;ek;kd;gkdkd;gdkg;d
}
};

and for some reason, it is compiling fine, even with the 'garbage' in
the function body. Somehow it doesn't see my logic in the body of the
function in compile time. Why? Any help? I am using CC 5.3 (Forte
Developer 6.0 under Solaris 8).

Thanks!

-RB
 
M

mrstephengross

Since your class is templatized, only a first-pass parse is performed.
The first-pass is simply a syntactic check, not a semantic one. Since
your "garbage" line technically consists of well-formed syntactic
tokens, the compiler doesn't complain.

If, however, you try to instantiate MyClass (ie: MyClass<SomeClass> t;
), the compiler will complain. This happens because when MyClass is
instantiated with a particular class T, the compiler *will*
semantically process the tokens in test().

--Steve
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top