background preloader

Core Language Issues

Facebook Twitter

Tutorials - The Static Keyword in C++ Most C++ keywords allow you to do one thing.

Tutorials - The Static Keyword in C++

You use int to declare an int, or that a function returns an int or expects an int as an argument. You use new to allocate memory, and delete to free memory. You use const to indicate that a variable's value cannot be changed. Ironically, the keyword static, though the word means "unchanging," has multiple (and apparently unrelated) uses. Keyword - When to use friend class in c++ Inheritance - Why does C++ not allow inherited friendship.

C/C++ private array initialization in the header file. Tech Talk about C++ Templates / Comeau C++ Template FAQ. Copyright © 2000-2008 Comeau Computing.

Tech Talk about C++ Templates / Comeau C++ Template FAQ

All rights reserved. Note that this is a live web page, in the sense that we'll be adding new discussions as appropriate, so stop by from time to time. This web page is evolving (Version 1.6, August 6, 2008), so if you see something not right, or have a question that is appropriate (note this FAQ is not a templates tutorial) please email us about it. . C++ Programming/RTTI. Run-Time Type Information (RTTI)[edit] RTTI refers to the ability of the system to report on the dynamic type of an object and to provide information about that type at runtime (as opposed to at compile time), when utilized consistently can be a powerful tool to ease the work of the programmer in managing resources. dynamic_cast[edit] Consider what you have already learned about the dynamic_cast keyword and let's say that we have the following class hierarchy:

C++ Programming/RTTI

Determining the Size of Class Objects. By Girish Shetty There are many factors that decide the size of an object of a class in C++.

Determining the Size of Class Objects

These factors are: Size of all non-static data members Order of data members Byte alignment or byte padding Size of its immediate base class The existence of virtual function(s) (Dynamic polymorphism using virtual functions). The C++ 'const' Declaration: Why & How. The 'const' system is one of the really messy features of C++.

The C++ 'const' Declaration: Why & How

It is simple in concept: variables declared with ‘const’ added become constants and cannot be altered by the program. However it is also used to bodge in a substitute for one of the missing features of C++ and there it gets horridly complicated and sometimes frustratingly restrictive. The following attempts to explain how 'const' is used and why it exists. C++ - Inheriting from a template class, using a type defined in the derived class.

C++ - Nested templates with dependent scope. A Quick Look at References and Constants. Use struct to create a boolean type. Algorithm Tutorials. The Best Questions for Would-be C++ Programmers, Part 1 It seems that an almost obligatory and very important part of the recruitment process is "the test.

Algorithm Tutorials

" "The test" can provide information both for the interviewer and the candidate. The interviewer is provided with a means to test the candidate's practical know-how and particular programming language understanding; the candidate can get an indication of the technologies used for the job and the level of proficiency the company expects and even decide if he still wants (and is ready for) the job in question. I've had my fair share of interviews, more or less successful, and I would like to share with you my experience regarding some questions I had to face. I also asked for feedback from three of the top rated TopCoder members: bmerry , kyky and sql_lall , who were kind enough to correct me where I was not accurate (or plain wrong) and suggest some other questions (that I tried to answer to my best knowledge). References. Algorithm Tutorials. The Best Questions for Would-be C++ Programmers, Part 2 ... read Part 1 In the second part of this installment we'll tackle some questions regarding more advanced features of the language (the experienced C++ programmers will consider some of these more on the basic side).

Algorithm Tutorials

So let's get to it and work on the second part of this "interview". That was it, folks! I hope that even if those questions did not pose any challenges, you still had fun doing/reading this quiz and refreshing your memory on some aspects of the C++ language. Notes. Copy constructor. Definition[edit] X(const X& copy_from_me); X(X& copy_from_me); X(volatile X& copy_from_me); X(const volatile X& copy_from_me); X(X& copy_from_me, int = 0); X(const X& copy_from_me, double = 1.0, int = 42); ...

Copy constructor

Using Namespaces in C. One of C++'s less heralded additions is addition of namespaces, which can be used to structure a program into "logical units".

Using Namespaces in C

A namespace functions in the same way that a company division might function -- inside a namespace you include all functions appropriate for fulfilling a certain goal. For instance, if you had a program that connected to the Internet, you might have a namespace to handle all connection functions: namespace net_connect { int make_connection(); int test_connection(); //so forth... } Strcspn. Const Correctness Question in C++ Constant data members. Jan 5, 2009 at 4:50pm Jan 5, 2009 at 3:50pm UTC Can data members be constant (with const) so that they are given a value by the constructor and them cannot be changed?

constant data members

If yes, can a data member be static const? (I'm asking the second question because a static member is defined outside the class while constant variables have to be defined and declared in one line) Jan 5, 2009 at 5:23pm Jan 5, 2009 at 4:23pm UTC. Tutorial: Pointers in C and C++ Using Variables Essentially, the computer's memory is made up of bytes. Each byte has a number, an address, associated with it. [SOLVED] Extern String Variable - C And C++ 8.12 — Static member functions.

In the previous lesson on static member variables, you learned that classes can have member variables that are shared across all objects of that class type. However, what if our static member variables are private? Consider the following example: In this case, we can’t access Something::s_nValue directly from main(), because it is private. Normally we access private members through public member functions. While we could create a normal public member function to access s_nValue, we’d then need to instantiate an object of the class type to use the function!

Like static member variables, static member functions are not attached to any particular object. Because static member functions are not attached to a particular object, they can be called directly by using the class name and the scope operator. Static member functions have two interesting quirks worth noting. Set pointer to null through function.

Arrays

C++ - Why can't I have a non-integral static const member in a class. C++ - What is the difference between exit() and abort() An odd C++ error: test.cpp:15: error: passing ‘const *’ as ‘this’ argument of ‘*’ discards qualifiers. C++ Tutorial - Lesson 22: Mutable Members. Assert. If the argument expression of this macro with functional form compares equal to zero (i.e., the expression is false), a message is written to the standard error device and abort is called, terminating the program execution. The specifics of the message shown depend on the particular library implementation, but it shall at least include: the whose assertion failed, the name of the source file, and the line number where it happened. A usual expression format is: Assertion failed: expression, file filename, line line number This macro is disabled if, at the moment of including <assert.h>, a macro with the name NDEBUG has already been defined.

This allows for a coder to include as many assert calls as needed in a source code while debugging the program and then disable all of them for the production version by simply including a line like: Exit code - How to quit a C++ program.