I have a table of C++ operator precedence, and it's causing errors.
From what I can see, line 9 is a problem, but I cannot see why [] would not properly escape []
I'm sure there are plenty of errors, so any fixes would be greatly appreciated.
\input{preamble.tex}
\begin{document}
\mainmatter
\begin{tabular}{l|l|l|l}
Precedence & Operator & Description & Associativity \\
1 & :: & Scope resolution & Left-to-right \\
2 & ++ -- \\
\(\) Function call \\
\[\] Array subscripting \\
. Element selection by reference \\
\-> Element selection through pointer \\
& postincrement and decrement & type\(\) type\{\} Function-style type cast \\
3 & ++ -- \\
+ - Unary plus and minus \\
! ~ Logical NOT and bitwise NOT \\
(type) C-style type cast \\
* Indirection (dereference) \\
\& Address-of \\
sizeof \\
new \\
delete
& Preincrement and decrement & Right-to-left \\
4 & .* ->* & Pointer to member & Left-to-right \\
5 & * / \% & Multiplication, division, and remainder \\
6 & + - & Addition and subtraction \\
7 & << >> & Bitwise left shift and right shift \\
8 & < <=
> >=
& Relational operators \\
Relational operators > ≥ respectively \\
9 & == != & For relational = and ≠ respectively \\
10 & \& & Bitwise AND \\
11 & ^ & Bitwise XOR \\
12 & | & Bitwise OR \\
13 & \&\& & Logical AND \\
14 & || & Logical OR \\
15 & ?:
throw
= Direct assignment (provided by default for C++ classes)
+= -= Assignment by sum and difference
*= /= \%= Assignment by product, quotient, and remainder
<<= >>= Assignment by bitwise left shift and right shift
\&= ^= |= Assignment by bitwise AND, XOR, and OR
& Ternary & Right-to-left \\
16 & , & Comma & Left-to-right
\end{tabular}
\end{document}
When I get rid of the backslashes on the parentheses, there is still an error on line 9:
! Missing number, treated as zero. } l.9 [] Array subscripting \ ? ! Illegal unit of measure (pt inserted).
The new (stripped) code is:
\input{preamble.tex}
\begin{document}
\mainmatter
\begin{tabular}{l|l|l|l}
Precedence & Operator & Description & Associativity \\
1 & :: & Scope resolution & Left-to-right \\
2 & ++ -- \\
() Function call \\
[] Array subscripting \\
. Element selection by reference \\
-> Element selection through pointer \\
& postincrement and decrement & Function-style type cast \\
OK, given the answer I cleaned up the table a lot, including making it standalone so anyone can copy it to learn from.
\documentclass{standalone}
\begin{document}
%\tiny
%\begin{tabular}{l|l|l|l}
\begin{tabular}{llll}
{\huge Precedence} & {\huge Operator} & {\huge Description} & {\huge Associativity} \\ \hline
1 & \verb$::$ & Scope resolution & Left-to-right \\
2 & \verb$++$ \verb$--$ & pre-increment and decrement & \\ \hline
& \verb$()$ & Function call & \\
& \verb$[]$ & Array subscripting & \\
& \verb$.$ & Object member & \\
& \verb$->$ & Element selection through pointer \\
& \verb$()$ & Function-style type cast \\ \hline
3 & \verb$++$ \verb$--$ & post-increment and decrement & Right-to-left \\
& \verb$+$ \verb$-$ & Unary plus and minus \\
& \verb$!$ \verb$~$ & Logical NOT and bitwise NOT \\
& (type) & C-style type cast \\
& \verb$*$ & Pointer dereference \\
& \verb$&$ & Address-of \\
& sizeof & The number of atomic units of memory used \\
& new & dynamic memory allocation \\
& delete & dynamic memory deallocation \\
4 & \verb$.*$ \verb$->*$ & Pointer to member & Left-to-right \\ \hline
5 & \verb$*$ \verb$/$ \verb+\%+ & Multiplication, division, and remainder \\ \hline
6 & \verb$+$ \verb$-$ & Addition and subtraction \\ \hline
7 & \verb$<<$ \verb$>>$ & Bitwise left shift and right shift \\ \hline
8 & \verb$<$ \verb$<=$ & Relational operators \verb$>$ \verb$≥$ \\
& \verb$>$ \verb$>=$ & Relational operators \verb$\greaterequal$ \verb$≥$ \\ \hline
9 & \verb$==$ \verb$!=$ & Relational equality and inequality \verb$≠$ \\ \hline
10 & \verb$&$ & Bitwise AND \\ \hline
11 & \verb$^$ & Bitwise XOR \\ \hline
12 & \verb$|$ & Bitwise OR \\ \hline
13 & \verb$&&$ & Logical AND \\ \hline
14 & \verb$||$ & Logical OR \\ \hline
15 & \verb$?:$ & ternary & Right-to-left \\
& throw & throw an exception \\
& \verb$=$ & assignment \\
& \verb$+=$ \verb$-=$ & additive assignment \\
& \verb$*=$ \verb$/=$ \verb$\%=$ & Multiplicative assignment \\
& \verb$<<=$ \verb$>>=$ & Bitwise left shift and right shift assignment \\
& \verb$\&=$ \verb$^=$ \verb$|=$ & Bitwise AND, XOR, and OR assignment \\ \hline
16 & \verb$,$ & Comma & Left-to-right \\
\end{tabular}
\end{document}
\(\)
and\[\]
are math delimiters. Do you want to show them as such?()
and[]
(No need to escape them)