By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,130 Members | 1,365 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,130 IT Pros & Developers. It's quick & easy.

Templates - Garbage In Garbage Not Out

P: n/a
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

Jul 25 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

Jul 25 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.