SunQuest
 
       C++
  Home arrow C++ arrow Page 4 - C++ Programming Tips
IBM developerWorks
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

C++ Programming Tips
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-03-12

    Table of Contents:
  • C++ Programming Tips
  • Modifying Objects
  • Advanced Parameter Passing
  • List
  • Pointers and Dynamic Memory

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    C++ Programming Tips - List


    (Page 4 of 5 )

    Character strings or string class strings

    If you use the string class, you have a more extensive set of capabilities than if you use character strings.

    Generic vector extraction

    Consider the following:

    Template (class T)

    Void GetValues(vector<T> &A)

    {

    A.resize(0);

    T Val;

    While (cin >> Val)

    {

    A.push_back(Val);

    }

    }


    The syntax template <class T> indicates that what follows is a generic form. In this situation, the form of the function is given. This function template allows different functions to be instantiated based on the particular type of vector used as the actual parameter. For example, if we have the following definitions:

    vector<int> X;

    vector<float> Y;


    the invocations


    GetValues(X);

    GetValues(Y);


    cause functions


    void GetValues(vector<int> &A)

    {

    A.resize(0);

    int Val;

    while (cin >> Val)

    {

    A.push_back(Val);

    }

    }


    void GetValues(vector<float> &A)

    {

    A.resize(0);

    float Val;

    while (cin >> Val)

    {

    A.push_back(Val);

    }

    }

    to be defined and invoked.


    Accessing multidimensional arrays

    Multidimensional arrays are stored in row-major order. Often contiguous sections of memory, called pages, are brought in with the expectation that values near a desired value are more likely to be referenced than values defined elsewhere in memory. Since a page is contiguous memory, it is more likely to contain a complete row than a complete column. So it is generally more efficient to process array elements row-by-row rather than column-by-column. This efficiency comes about in how memory values are brought into the central processing unit, as explained above.

    More C++ Articles
    More By Chrysanthus Forcha


       · This article gives a C++ programmer confidence. After reading the article, you will...
     

    C++ ARTICLES

    - Large Numbers
    - Dijkstra`s Shunting Algorithm with STL and C...
    - Brief Introduction to the STL Containers
    - The Standard Template Library
    - Templates in C++
    - C++ Programmer Alerts
    - C++ Programming Tips
    - First Steps in (C) Programming, conclusion
    - First Steps in (C) Programming, continued
    - First Steps in (C) Programming, introduction
    - C++ Preprocessor: Always Assert Your Code Is...
    - C++ Preprocessor: The Code in the Middle
    - Programming in C
    - Temporary Variables: Runtime rvalue Detection
    - Temporary Variables: Chasing Temporaries Away







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway