Wednesday 9 April 2014

Common syntax errors in C++

These are some regular punctuation failures that were acknowledged by some more established compilers yet are accounted for and dismisses by fresher variants, especially g++ Version 4. 

My formats FAQ blankets some different issues identified with sentence structure and name look up in layouts that can show up when redesigning or exchanging compiler.

Reliance on friend name injection

The Annotated Reference Manual (ARM), an early depiction of C++, expressed that a revelation companion works in a class was dealt with as a presentation in the encompassing namespace (this is called "companion name infusion"). 

This is an exemption to the general decide that names must be characterized or over-burden in a square connected with the extension they are characterized in. It has especially odd impacts for class formats, as a companion announcement in a class format might be instantiated alongside whatever remains of the layout. 

In standard C++, companion name infusion is not performed. Companion works that need to be found by common name gaze toward (restricted to contention ward find) should first be proclaimed in the class' namespace.

Wrong      

          class foo;

class bar
{
    // ...
    foo * foo _;
};

class foo
{
    // ...
    friend int baz(const bar &);
};

int main()
{
    return baz(bar()); 
}             


Right 
             class foo;

class bar
{
    // ...
    foo * foo _;
};

class foo
{
    // ...
    friend int baz(const bar &);
};

int baz(const bar &);

int main()
{
    return baz(bar()); 
}
               
       "News Powered By"

              

Share:

No comments:

Post a Comment

© World Of Programmers All rights reserved | Theme Designed by Seo Blogger Templates