Content deleted Content added
m →Semantics: {{code}} |
m →Syntax: {{nowrap}} |
||
Line 103:
=== Syntax ===
{{see also|Java syntax|C++ syntax}}
* [[Java syntax]] has a [[context-free grammar]] that can be parsed by a simple [[LALR parser]]. Parsing C++ is more complicated. For example, {{nowrap|<code>Foo<1>(3);</code>}} is a sequence of comparisons if Foo is a variable, but creates an object if Foo is the name of a class template.
* C++ allows namespace-level constants, variables, and functions. In Java, such entities must belong to some given type, and therefore must be defined inside a type definition, either a class or an [[interface (Java)|interface]].
* In C++, objects are values, while in Java they are not. C++ uses ''value semantics'' by default, while Java always uses ''reference semantics''. To opt for reference semantics in C++, either a pointer or a reference can be used.
Line 112:
|-
| <syntaxhighlight lang="cpp">
class Foo {
int x = 0;
public:
Foo(): x{0}
{}
int bar(int i) { // Member function bar()
|