Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 25th, 2005, 05:45 PM
ramiro_b@yahoo.com
Guest
 
Posts: n/a
Default Templates - Garbage In Garbage Not Out

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

  #2  
Old July 25th, 2005, 05:55 PM
mrstephengross
Guest
 
Posts: n/a
Default Re: Templates - Garbage In Garbage Not Out

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

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles