"Первая попытка" не компилируется, пока выполняется вторая. Зачем? Какая разница?
Первая попытка:
#include <iostream>
int main()
{
constexpr const char text2[] = "hello";
constexpr const char * b = &text2[4]; // error: '& text2[4]' is not a constant expression
std::cout << b << std::endl;
}
Вторая попытка:
#include <iostream>
int main()
{
constexpr const char * text1 = "hello";
constexpr const char * a = &text1[4];
std::cout << a << std::endl;
return 0;
}
Я компилирую с (g++ версия 4.9.2)
g++ -std=c++11 -o main *.cpp
который дает следующую ошибку
main.cpp: In function 'int main()':
main.cpp:7:40: error: '& text2[4]' is not a constant expression constexpr const char * b = &text2[4]; // error: '& text2[4]' is not a constant expression