Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ define constant in class header

class Foo
{
public:
    const int a = 5; // Valid use of const.
    constexpr int b = 7; // Invalid use of constexpr, won't even compile!
    static constexpr int c = 10; // Valid use of constexpr.

    int arrA[a]; // ERROR: 'a' is defined at runtime, so you can't use it to define a size.
    int arrB[b]; // ERROR: You couldn't even define 'b', so this is not going to work...
    int arrC[c]; // VALID: 'c' is known by the compiler, and is guaranteed to only ever be 10!
}
Comment

c++ define constant

#include <iostream>
using namespace std;

#define PI 3.14159
#define NEWLINE '
'

int main ()
{
  double r=5.0;               // radius
  double circle;

  circle = 2 * PI * r;
  cout << circle;
  cout << NEWLINE;

}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Comment

PREVIOUS NEXT
Code Example
Cpp :: C++ String Concatenation Example 
Cpp :: how to use for c++ 
Cpp :: stoi in c++ 
Cpp :: opengl draw house using glut c++ 
Cpp :: Basic Input / Output in C++ 
Cpp :: cout stack in c++ 
Cpp :: c++ stl vector get iterator from index 
Cpp :: inline function in cpp 
Cpp :: what is throw in c++ 
Cpp :: c++ convert to assembly language 
Cpp :: swap alternate elements in an array c++ problem 
Cpp :: C++ Nested if 
Cpp :: C++ vector at() method 
Cpp :: c++ program to find gcd of 3 numbers 
Cpp :: how to insert in a queue c++ 
Cpp :: c++ class constructor variable arguments 
Cpp :: ? in cpp 
Cpp :: how to modify 2d array in function c++ 
Cpp :: replace a char in string c++ at a specific index 
Cpp :: cout in c++ 
Cpp :: bool nullable to bool c# 
Cpp :: HMC 5883 Example to return x y z values 
Cpp :: the amount of input is unknown 
Cpp :: use textchanged qt cpp 
Cpp :: how you can add intger value to string in c++ 
Cpp :: windows servis from console app 
Cpp :: decemal representation 
Cpp :: grepper users assemble 
Cpp :: how to type cast quotient of two integers to double with c++ 
Cpp :: Fill 2-dimensional array with value 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =