IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesC++  Print This     

C++ and PHP Cross Reference Guide

By Mike Prestwood

C++ versus PHP: A side by side comparison between C++ and PHP.

C++

Version: This content is based on Visual C++ and/or C++Builder and was tested in Microsoft Visual Studio.Net 2008 and/or C++Builder 2009. 

This content focuses on topics in common among the languages documented here so nearly all this syntax applies to other C++ development environments as well as earlier versions of C++.

Much of Java's syntax will look similar to both Java and C# but there are significant differences.

Note: To be clear, the subject of this information is generic C++ and all code snippets are based on either Visual C++ by Microsoft or C++Builder by CodeGear (or both). Although much of the information applies to other C++ tools, we only verified the syntax and information within Visual C++ and C++Builder.

PHP

Version: This content is based on PHP 5 and tested using our web hosting server farm. The focus of this content is on server-side scripting.

This content focuses on topics in common among the languages documented here so nearly all this syntax applies to most PHP development environments as well as earlier versions of PHP.

Some of PHP's syntax will look similar to Perl but with significant differences.

Note: To be clear, the subject of this information is generic PHP 5 and in some cases Delphi for PHP. Although much of the information applies to other PHP tools, we only verified the syntax and information within generic PHP and/or Delphi for PHP.

 
Tool Basics
 

Developer environment basics such as common file extensions, common keyboard shortcuts, etc.

Deployment Overview

[Other Languages] 
C++: 

You can use any of the many free and commercially available installation packages.

In Visual Studio.Net, you can create a Setup and Deployment project by using any of the templates available on the New Project dialog (Other Project Types).

C++Builder 2007 and 2009 are bundled with InstallAware Express CodeGear Edition installer.

More Info / Comment
PHP: 

With PHP, you simply copy your files to a web server that is capable of running PHP pages.

More Info / Comment




Development Tools

[Other Languages] 

Languages Focus

Primary development tool(s) used to develop and debug code.

C++: 

Many compilers and development tools are available. Common development tools include Microsoft Visual C++, CodeGear C++Builder, and Eclipse.

With Visual C++ you use Microsoft's C++ syntax variations based on standard C++ or Microsoft's new C++/CLI syntax standard.

With C++Builder, you code using standard C++ with early support for the upcoming C++0x standard and using the VCL/RTL libraries. The VCL/RTL libraries are in common with Delphi which is based on Object Pascal. Within a project, C++Builder can use both C++ units and Delphi units.

With most C++ tools, you can also use your favorite C and C++ libraries too.

More Info / Comment
PHP: 

Many developers just use a text editor. There are many PHP editors available including phpDesigner, and Delphi for PHP.

More Info / Comment




File Extensions

[Other Languages] 

Languages Focus

Common or primary file extensions used (not a complete list, just the basics).

C++:   .CPP and .H

Important standard C++ file extensions:

  • .CPP = C++ Source file. Your startup source file will have a main() routine.
  • .C = C source file (sometimes used for C++ source files too).
  • .H = Header include file.

Some important Visual C++ file extensions:

Some important C++Builder file extensions:

  • .BDSPROJ and .CBPROJ = Project file.
More Info / Comment
PHP:   .php

.php is the default extension for PHP although some developers will change the default extension in an effort to add an additional security level. If your code is tied to a particular version of PHP then some developers at the major PHP version number to the extension as in .php3, .php4, .php5, etc. 

.phtml is also sometimes used especially for files that contain both HTML and Perl code.

More Info / Comment




Overview and History

[Other Languages] 
C++: 

Language Overview: C++ is a hybrid traditional C and OOP language. You code either in a traditional approach using functions, procedures, and global data, or you code using an OOP approach, or a mixture of both.

Target Platforms: C++ is suitable for creating any type of native code applications for many different platforms. The focus of this information is on creating native code Win32 applications that run on Microsoft Windows.

More Info / Comment
PHP: 

PHP is a hybrid language with both traditional PHP and OOP features. PHP is widely-used general-purpose scripting language that is especially suited for web development and can be embedded into HTML. PHP has been used to create some amazing web content, particularly outstanding message boards.

Target Platforms: PHP is most suitable for creating websites targeting any browser (any web server with PHP installed).

More Info / Comment




Report Tools Overview

[Other Languages] 

Languages Focus

Built-In: Some development tools have a reporting tool built-in and some do not. For example, typically desktop databases such as Paradox and Access have a built-in reporting tool and typically that reporting tool is used with nearly every application built with it. A built-in reporting tool makes development of reports across many clients and applications consistent and therefore easy.

Add-On: Development tools that do not have a built-in reporting tool need to use either a currently bundled report writer, or one of the popular reporting tools that integrates well with the development tool. For example, popular reporting tools include Crystal Reports, ReportBuilder, and MS SQL Reporting Services (tied to MS SQL).

C++: 

Use any report writer you are comfortable with. C++Builder 2009 comes bundled with Rave Reports and Crystal Reports remains popular for Visual C++.

More Info / Comment
PHP: 

No built-in report writer but because website development targets a client browser (a document interfaced GUI), a common solution is to simply output an HTML formatted page with black text and a white background (not much control but it does work for some situations).

More Info / Comment




 
Language Basics
 

Language basics is kind of a catch all for absolute beginner stuff. The items (common names) I chose for language basics is a bit random and include items like case sensitivity, commenting, declaring variables, etc.

Case Sensitivity

[Other Languages] 

Languages Focus

Case sensitiviy in this case is referring to commands and variable names. For example, are "printf" and "PrintF" equivalent? Are fullname and FullName equivalent? When you create commands, operations, methods, or variables should you worry about case?

C++:   Yes

C++ is case sensitive. In C and C++ commands and variable names are case sensitive.

Syntax Example:

The following first standard C++ snippet works:

printf("hello\n");
 
Printf("hello\n"); //>>>Does not work!
PHP:   Yes and No

PHP is case sensitive with variable names but not with commands. Although commands are case incenstive, I prefer to use all lowercase because it's easy to type and that's what I see most PHP coders doing and I see it on PHP.Net.

Syntax Example:

All of the following are equivalent:

echo "hello<br>";
ECHO "hello<br>";
Echo "hello<br>";
eCHo "hello<br>";

...but variables are case sensitive:

$fullname = "Mike Prestwood"; //These are two...
$FullName = "Wes Peterson";   //separate varialbes.




Code Blocks

[Other Languages] 

Languages Focus

The rules for code blocks within a language dictate where you can declare variables, how you "bracket" code, etc.

C++:   { }

For C++, Java, JavaScript, and PHP, I will use Berkeley indent style only because I see more C++ code formatted that way.

Syntax Example:
int Dog::Bark() {
cout << "My first class method!" << endl;
return 0;
};
PHP:   { }

In .PHP html pages, you embed PHP code between <?PHP and ?>.

For PHP, JavaScript, Java,and C++, I prefer to put the first { at the end of the first line of the code block as in the example above because I see morePHP codeformatted that way (and on PHP.Net).

PHP Alternative Syntax

Although I don't like to use it, PHP offers an alternative syntax for if, while, for, foreach, and switch. These code blocks are surrounded by statement ending keywords that all use End with camel caps such as endif, endwhile, endfor, endforeach,and endswitch.

Syntax Example:
<?PHP
$x = "Yes";
//Simple if
If ($x == "Yes")
echo "hello world";
 
//If with a block of code.
If ($x == "Yes") {
echo "Hello world";
  echo "I am a PHP coder!";
}
?>




Comments

[Other Languages] 

Languages Focus

Commenting code generally has three purposes: to document your code, for psuedo coding prior to coding, and to embed compiler directives. Most languages support both a single line comment and a multiple line comment. Some languages also use comments to give instructions to the compiler or interpreter.

C++:   // or /* ... */

Commenting Code
C++ uses "//" for a single line comment and /* */ for a multiple line comment.

Syntax Example:
//Single line comment in MS (not ANSI compliant so do NOT use).
/* ANSI compliant single line comment. */
/*
Multiple line
comment.
*/
  
/*
* This is another popular
* way to write multi-line
* comments.
*/
PHP:   # or // or /* ... */

Commenting Code
Use the multi-line to comment out large blocks of code and to write multiple line comments.

Syntax Example:
#This is a comment in PHP.

//This is too!

/*
This is a multi-line
comment.
*/




Constants

[Other Languages] 

General Info: Computer Language Constants

A constant is just like a variable (it holds a value) but, unlike a variable, you cannot change the value of a constant.

C++:   const

In standard C++, you use const and static const to declare constants.

Syntax Example:
//C++Builder 2009 Example:
const String kName = "Mike";
const int kAge = 35;
  
ShowMessage("Hi " + kName + ", you are " + kAge + ".");
PHP:   define

In PHP, you declare constants using the define keyword:

define("CONST_NAME", "Value");

Constants in PHP are case sensitive. A common standard in PHP is to use all-uppercase letters, with underscores to separate words within the name.

Syntax Example:
define('FULL_NAME', 'Mike Prestwood');
define("AGE", 25);
  
echo "Your name is " . FULL_NAME . ".";
echo "You are " . AGE . ".";




End of Statement

[Other Languages] 

Languages Focus

In coding languages, common End of statement specifiers include a semicolon and return (others exist too). Also of concern when studying a language is can you put two statements on a single code line and can you break a single statement into two or more code lines.

C++:   ;

C++ uses a semicolon ";" as an end of statement specifier and you can put multiple statements on a single line of code if you wish as well as split a single statement into two or more code lines.

Syntax Example:
printf("Hello1");
printf("Hello2");
  
printf("Hello3"); printf("Hello4");
  
printf
   ("Hello5");
PHP:   ;
Syntax Example:
echo "Hello";




Literals

[Other Languages] 

General Info: Programming Literals

A value directly written into the source code of a computer program (as opposed to an identifier like a variable or constant). Literals cannot be changed. Common types of literals include string literals, floating point literals, integer literals, and hexidemal literals. Literal strings are usually either quoted (") or use an apostrophe (') which is often referred to as a single quote. Sometimes quotes are inaccurately referred to as double quotes.

Languages Focus

In addition to understanding whether to use a quote or apostrophe for string literals, you also want to know how to specify and work with other types of literals including floating point literals. Some compilers allow leading and trailing decimals (.1 + .1), while some require a leading or trailing 0 as in (0.1 + 0.1). Also, because floating point literals are difficult for compilers to represent accurately, you need to understand how the compiler handles them and how to use rounding and trimming commands correctly for the nature of the project your are coding.

C++:   quote

String literals are quoted as in "Prestwood". If you need to embed a quote use a slash in front of the quote as in \".

Syntax Example:
printf("Hello\n");
printf("Hello \"Mike\".\n");
 
cout << "Hello" << endl;
cout << "Hello \"Mike\".\n";
PHP:   quote or apostrophe

In PHP you can use quotes, or apostrophes as in "Prestwood", and 'Prestwood' for string literals. Use a slash in front of a quote or apostrophe to embed same type as in \' and \".

To specify a floating point literal between 1 and -1, you can preceed the decimal with a 0 or not (both work). In other words, preceding and following decimals are allowed (both .1 and 0.1). Trailing decimals are also allowed (1, 1., and 1.0 are all equivalent and allowed).

Syntax Example:
echo "Mike's drums are over there.<br>";
echo 'Mike said, "hi!"<br>';
  
//Does PHP evaluate this simple
//floating point math correctly? No! 
If ((.1 + .1 + .1) == .3) {
 Echo "Correct";
} Else {
 Echo "Not correct";
}




Variables

[Other Languages] 

Languages Focus

A variable holds a value that you can use and change throughout your code so long as the variable is within scope. With variable declaration, you not only want to know the syntax of how you declare a variable but you also want to know where. Are you allowed to declare a variable inline? What are the available scopes: local vs. global. Can you assign a value at the same time you declare a variable?

C++:   int x=0;

Variable names are case sensitive.

The fundamental variable types in C++ are char, short int, int, long int, bool, float, double, long double, and wchar_t. The integer data types char, short, long and int can be either signed or unsigned. Signed variables are positive and negative. Unsigned variables are positive only.

Syntax Example:

C++, Java, and C# all use C-like variable declaration.

int Age;
int Age = 43;
float a, b, c;
string FullName; //#include 
unsigned short int FamilyMemberCount;
PHP:   $x = 0;

PHP is a loosely typed language. No variable types in PHP. Declaring and using variables are a bit different than in other languages. In PHP, you identify and use a variable with a $ even within strings!

You assign by reference with & as in &$MyVar.

Syntax Example:
$fullname = 'Mike Prestwood';
$FullName = 'Wes Peterson'; //This is a different variable!
$Age = 38;
$Weight = 162.4;
 

echo "Your name is $fullname.
";
echo "You are $Age and weigh $Weight.
";




 
Language Details
 

Language Details is kind of a catch all for stuff that didn't make it into language basics nor any other category.

Custom Routines

[Other Languages] 

Languages Focus

For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.

C++: 

C++ is a hybrid language and as such offers global functions and class methods. A function must come before it's usage or you can prototype the function.

Syntax Example:
void sayHello(string pName) {
cout << "Hello " + pName + "\n";
};
 
int add(int p1, int p2) {
int result;
 
  result = p1 + p2;
return result;
};
PHP:  "Custom Function" function

PHP uses functions and loosely typed parameters. Function definitions can come before or after their usage so my preference when mixing PHP in with a mostly HTML page is to put the functions after the </html> tag.

Syntax Example:
function sayHello($pName) {
 echo "Hello " . $pName . "<br>";
}
 
function add($p1, $p2) {
 return $p1 + $p2;
}




Inlining

[Other Languages] 

General Info: Inline Routines

Instead of calling a routine, you move the code from the routine itself and expand it in place of the call. In addition to manual inlining, some languages support automatic inlining where the compiler or some other pre-compiler decides when to inline a code routine. Also, some languages allow for developer defined inlining where the developer can suggest and/or force the inlining of a code routine. Inlining can optimize your code for speed by saving a call and return, and parameter management.

Languages Focus

Does it support inlining? If so, does it support developer defined inlining? Does it support automatic inlining? Both?

C++:   inline

In both Visual C++ and C++Builder, use the inline (standard C++) or __inline (standard C and C++) keywords to suggest to the compiler to inline a routine.

Microsoft also offers __forceinline and _inline, Microsoft specific specifiers where __forceinline is a stronger suggestion but still does not always mean the routine will be inlined as well as _inline for backward compatibility.

Syntax Example:
inline int add(int p1, int p2) {
int result;
 
  result = p1 + p2;
return result;
};
[Not specified yet. Coming...]




Overloading

[Other Languages] 

Types of overloading include method overloading and operator overloading.

Method Overloading is where different functions with the same name are invoked based on the data types of the parameters passed or the number of parameters. Method overloading is a type of polymorphism and is also known as Parametric Polymorphism.

Operater Overloading allows an operator to behave differently based on the types of values used. For example, in some languages the + operator is used both to add numbers and to concatenate strings. Custom operator overloading is sometimes referred to as ad-hoc polymorphism.

C++: 

C++ Overloading

  • Operator - Yes for C++, no for C. Almost all operators can be overloaded for user-defined types
  • Method -
PHP: 

PHP

  • Operator - No.
  • Method -
Syntax Example:

 





Self Keyword

[Other Languages] 
C++:   this
[Not specified yet. Coming...]




 
Data Structures
 

Data structures allow you to store and work with data. Common data structures include arrays, associative arrays, etc.

Associative Array

[Other Languages] 
A set of unique keys linked to a set of values. Each unique key is associated with a value. Think of it as a two column table. MyArray['CA'] = 'California' MyArray['AR'] = 'Arizona'

Languages Focus

Associative arrays are also known as a dictionary or a hash table in other languages.

C++:   map
Syntax Example:
map<string, int> mymap;
mymap.insert(AValuePair);
PHP: 

Declare associative array with initial known values. You can also add to associative array. (You can just assign values without ever declaring it too!)

Syntax Example:
$prices = array( 'Tires'=>100, 'Spark Plugs'=>4 );
$prices['Oil'] = 10;
 
echo "Tires=" . $prices['Tires'] . "<br>";
echo "Oil=" . $prices['Oil'] . "<br>";




Pointers

[Other Languages] 

General Info: Pointers / References

A pointer is a variable type that allows you to refer indirectly to another object. Instead of holding data, a pointer holds the address to data -- the address of another variable or object. You can change the address value a pointer points to thus changing the variable or object the pointer is pointing to.

A reference is a type of pointer that cannot change and it must always point to a valid storage (no nulls).

C++: 

C++ uses both pointers and references. Use the * operator to declare a pointer and use the & operator to declare a reference.

More Info / Comment
PHP:   Not Supported

PHP supports references which allow you to refer to the value of a variable but PHP does not support true developer defined pointers. You cannot get and use the address of a variable.

However, you can still do inexpensive assignments by assigning by reference.





 
Statements
 

Common statements such as if statements, loops, etc.

Exception Trapping

[Other Languages] 

Languages Focus

A common usage of exception handling is to obtain and use resources in a "try-it" block, deal with any exceptions in an "exceptions" block, and release the resources in some kind of "final" block which executes whether or not any exceptions are trapped.

C++:   try/catch
Syntax Example:
try {
  //Some code.
}
catch(AnError) {
  //Error code here.
}
[Not specified yet. Coming...]




If Statement

[Other Languages] 
C++:   if..else if..else

Same as standard C.

Syntax Example:
//C++Builder example using the VCL ShowMessage.
int x;
  
x = 8;
  
if (x == 10) {
ShowMessage("x is 10.");
} else if (x < 10) {
ShowMessage("x is less than 10.");
} else {
ShowMessage("x must be greater than 10.");
}
PHP:   if..elseif..else

The PHP if statement consists of using if, elseif, and else.

Syntax Example:
$x = 8;
  
if ($x == 10) {
 echo "x is 10."; 
} elseif ($x < 10) {
 echo "x is less than 10.";
} else {
 echo "x must be greater than 10."; 
};




 
Operators
 

A language symbol used for assignment, comparison, computational, or as a logical.

Assignment

[Other Languages] 

Languages Focus

Common assignment operators for languages include =, ==, and :=. An assignment operator allows you to assign a value to a variable. The value can be a literal value like "Mike" or 42 or the value stored in another variable or returned by a function.

C++:   =

C++ uses = for it's assignment operator.

Syntax Example:
int Age;
string FullName; //#include <string>
  
Age = 42;
FullName = "Randy Spitz";
PHP:   =

PHP uses = for it's assignment operator.

Syntax Example:
$fullname = "Randy Spitz";
$age = 38;




Comparison Operators

[Other Languages] 

General Info: Round Floating Point Numbers

When comparing floating point numbers, make sure you round to an acceptable level of rounding for the type of application you are using.

Languages Focus

A comparison operator compares two values either literals as in "Hello" and 3 or variables as in X and Counter. Most languages use the same operators for comparing both numbers and strings. Perl, for example, uses separate sets of comparison operators for numbers and strings.

C++:   ==, !=

Common comparison operators:

== equal
!= not equal
< less than
> greater than
<= less than or equal
>= greater than or equal

Syntax Example:
//C++Builder example (ShowMessage is a VCL method).
//Does C++Builder evaluate the math correctly? No!
If (.1 + .1 + .1 == .3)
ShowMessage("correct");
else
ShowMessage("not correct");
PHP:   ==, != or <>

Common comparison operators:

== equal
!= or <> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal

PHP 4 and above also offers === for indentical (equal plus same type) and !== for not identical (not equal or not same type).

Syntax Example:
//Does PHP evaluate the math correctly? No!
if (.1 + .1 + .1 == .3) {
echo "correct";
}
else {
echo "not correct";
}




Logical Operators

[Other Languages] 

Languages Focus

Logical operators perform conditional and, or, and not operations. Some languages support both binary logical operators that link two and unary logical operators negate (make opposite) the truth value of its argument. Finally, some languages short circuit logic. For example, with this or that, if this is an expression returning true, then that is never executed.

C++: 

C++ logical operators:

&& and, as in this and that
|| or, as in this or that
! Not, as in Not This
^ either or, as in this or that but not both

Syntax Example:
//Given expressions a, b, c, and d:
if !((a && b) && (c || d)) {
  //Do something.
}
PHP:   and, &&, or, ||, !, Xor

PHP logical operators:

and, && and, as in this and that
or, || or, as in this or that
! Not, as in Not This
Xor either or, as in this or that but not both

Syntax Example:
#Given expressions a, b, c, and d:
if !((a && b) && (c || d)) {
  #Do something.
};




String Concatenation

[Other Languages] 
C++:  "String Concatenation" + or append

The + operator can be used with any combination of C++ strings, C strings and characters.

Syntax Example:
string fullname;

fullname = "Mike ";
fullname.append("Prestwood");

cout << "Hello " + fullname + "." << endl;
PHP:  "String Concatenation" .

PHP uses a period (.) known as a dot to concatenate strings.

Syntax Example:
$fname = "Mike";
$lname = "Prestwood";

$fullname = $fname . $lname . "
";

echo "My name is " . "Mike.
";




Unary Operators

[Other Languages] 

General Info: Unary Operator

An operation with only one operand (a single input). Common unary operators include + plus, - minus, and bitwise not. Some operators can function as both unary and binary operators. For example, + and - operators can serve as either.

Languages Focus

What unary operators are supported in additoin to the standard plus, minus, and bitwise not.

C++: 

An operation with only one operand (a single input) such as ++X and --Y.

More Info / Comment
PHP: 

A unary operator operates on only one value.

PHP Examples:

  • ! negation operator
  • ++ increment operator
  • -- decrement operator




 
OOP Basics
 

Some languages support object-based concepts such as Paradox, Access, and VB Classic. Other languages have OO extensions and fully support object orientation in a hybrid fashion (such as C++ and Dephi for Win32). Finally, some lanages such as C#, VB.Net, Prism, and Java are entirely written in OO. Meaning, every line of code written must occur within a class).

Class..Object

[Other Languages] 

Languages Focus

In short, a class is a data type, and an object is an instance of a class type. A class has methods (routines), properties (member variables), and a constructor. The current values of the properties is the current state of the object. The UML is one of the diagraming disciplines that allows you to document the various changing states of a series of objects.

C++:   Yes More Info / Comment
[Not specified yet. Coming...]




Inheritance

[Other Languages] 

The concept of a class makes it possible to define subclasses that share some or all of the main class characteristics. This is called inheritance. Inheritance also allows you to reuse code more efficiently. In a class tree, inheritance is used to design classes vertically. (You can use Interfaces to design classes horizontally within a class tree.) With inheritance, you are defining an "is-a" relationship (i.e. a chow is-a dog). Analysts using UML call this generalization where you generalize specific classes into general parent classes.

C++:   : public ParentClass

In C++ you use the class keyword to signify a class and a colon followed by the parent class name for inheritance.

Syntax Example:

In the following example, a terminator T-600 is-an android. 

class Android {
};
 
class T-600: Public Android {
};
[Not specified yet. Coming...]




Member Visibility

[Other Languages] 

General Info: Class Visibility Specifiers

In OOP languages, members of a class have a specific scope that indicates visibility. Standard visibility includes private, protected, and public. Private members are usable by the defining class only (fully encapsulated). They are invisible outside of the class except by friendly classes. Protected members are usable by the defining class and descendant classes only (plus friendly classes). Public members are usable wherever its class can be referenced.

Languages Focus

Traditional member visibility specifiers for fully OOP languages are private, protected, and public. Many modern OOP languages implement additional member visibilities.

Additional member modifiers are documented under the Member Modifiers topic.

C++: 

C++ implements class and member visibility specifiers traditionally. Note the colon at the end of each visibility specifier and the semi-colon at the end of the class (the end of the statement).

Syntax Example:
class Cyborg: Public AParentClass {
public:
 
protected:
 
private:
};
[Not specified yet. Coming...]




 
OOP Details
 

More object oriented (OO) stuff.

Abstraction

[Other Languages] 

General Info: Abstract Class / Abstract Member

An abstract class member is a member that is specified in a class but not implemented. Classes that inherit from the class will have to implement the abstract member. Abstract members are a technique for ensuring a common interface with descendant classes. An abstract class is a class you cannot instantiate. A pure abstract class is a class with only abstract members.

Languages Focus

Abstraction is supported at various levels with each language. A language could enforce abstraction at the class level (either enforcing a no-instantiation rule or a only abstract members rule), and with class members (member methods and/or properties).

C++:   =0 in a virtual method

AbstractMemberFunction is a pure virtual function makes this class Abstract class indicated by the "=0"and NonAbstractMemberFunction1 is a virtual function.

Syntax Example:
class AbstractClass {
public:
virtual void AbstractMemberFunction() = 0;
  virtual void NonAbstractMemberFunction1();

};
[Not specified yet. Coming...]




Class Helper

[Other Languages] 

A. In Dephi, class helpers allow you to extend a class without using inheritance. With a class helper, you do not have to create and use a new class descending from a class but instead you enhance the class directly and continue using it as you always have (even just with the DCU).

B. In general terms, developers sometimes use the term to refer to any class that helps out another class.

C++:  "Class Helpers" Not Supported

However, developers sometimes use the term "class helper" to refer to code that helps out a class. Not truly the meaning we are using here, but you should be aware of the term's general usage.

[Not specified yet. Coming...]




Constructor

[Other Languages] 

General Info: Class Constructor

Constructors are called when you instantiate an object from a class. This is where you can initialize variables and put code you wish executed each time the class is created. When you initially set the member fields and properties of an object, you are initializing the state of the object. The state of an object is the values of all it's member fields and properties at a given time.

Languages Focus

What is the syntax? Can you overload constructors? Is a special method name reserved for constructors?

C++:  "Constructors" Use Class name

A member function with the same name as the class.

Syntax Example:  
class X {
public:
X(); // constructor for class X
};
[Not specified yet. Coming...]




Destructor

[Other Languages] 

General Info: Class Destructor

A special class method called when an object instance of a class is destroyed. With some languages they are called when the object instance goes out of scope, with some languages you specifically have to call the destructor in code to destroy the object, and others use a garbage collector to dispose of object instances at specific times.

Desctructors are commonly used to free the object instance but with languages that have a garbage collector object instances are disposed of when appropriate. Either way, destructors or their equivalent are commonly used to free up resources allocated in the class constructor.

Languages Focus

Are object instances freed with a garbage collector? Or, do you have to destroy object instances.

C++:   ~ClassName

A member function with the same name as the class prefixed with a ~ (tilde). C++ destructors are automatically called when an object goes out of scope, or when you delete a dynamically allocated object. Every class can have only one destructor.

Syntax Example:
class Cyborg {
public:
// Constructor for class Cyborg
Cyborg();
  
// Destructor for class Cyborg
~Cyborg();
};
[Not specified yet. Coming...]




Inheritance-Multiple

[Other Languages] 
C++:   Yes

C++ supports both multiple implementation inheritance and multiple interface inheritance.

More Info / Comment
[Not specified yet. Coming...]




Interface

[Other Languages] 

An element of coding where you define a common set of properties and methods for use with the design of two or more classes.

Both interfaces and abstract classes are types of abstraction. With interfaces, like abstract classes, you cannot provide any implementation. However, unlike abstract classes, interfaces are not based on inheritance. You can apply an Interface to any class in your class tree. In a real sense, interfaces are a technique for designing horizontally in a class hierarchy (as opposed to inheritance where you design vertically). Using interfaces in your class design allows your system to evolve without breaking existing code.

C++:  "Interfaces" No, but mimic it.

You can mimic an interface by using a class that has only pure-virtual functions and no member variables.

[Not specified yet. Coming...]




Partial Class

[Other Languages] 

A partial class, or partial type, is a class that can be split into two or more source code files and/or two or more locations within the same source file. Each partial class is known as a class part or just a part. Logically, partial classes do not make any difference to the compiler. The compiler puts the class together at compile time and treats the final class or type as a single entity exactly the same as if all the source code was in a single location.

Languages Focus

For languages that have implemented partial classes, you need to know usage details and restrictions. Can you split a class into two or more files? Can you split a class within a source code file into two or more locations? What are the details of inheritance? Does it apply to interfaces as well?

C++:  "Partial Classes" Not Supported

In C++, you can split the implementation of a class among two or more source files. However, you must declare the member in the class declaration.

[Not specified yet. Coming...]




Prevent Derivation

[Other Languages] 

Languages Focus

How do you prevent another class from inheriting and/or prevent a class from overriding a member.

C++: 

Make the constructor a private member of the class.

More Info / Comment
[Not specified yet. Coming...]




Static Member

[Other Languages] 

General Info: Static Class / Static Member

A static member is a member you can have access to without instantiating the class into an object. For example, you can read and write static properties and call static methods without ever creating the class. Static members are also called class members (class methods, class properties, etc.) since they belong to the class and not to a specific object. A static class is a class that contains only static members. In the UML, these classes are described as utility classes.

Languages Focus

Languages that support static members usually at least support static member fields (the data). Some languages also support static methods, properties, etc. in which case the class member is held in memory at one location and shared with all objects. Finally, some languages support static classes which usually means the compiler will make sure a static class contains only static members.

C++:  "Static Members" static

C++ supports static methods and static member fields.

Syntax Example:
class MyUtils {
public:
static void MyStaticMethod();
};
[Not specified yet. Coming...]




Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]