#include<stdio.h> #include<iostream> using namespace std; struct A { const int value_const() const{return 1;} const int value(){return 1;} }; int main() { A* const a1=new A; //const 修饰指针本身 const A*a2=a2=new A; //const 修饰指针 指向内容不可变;本身可变 //a1=new A; //wrong //a1=new A; //wrong a2=new A; a2=new A; cout<<a1->value()<<endl; cout<<a1->value_const()<<endl; //cout<<a2->value()<<endl;//wrong cout<<a2->value_const()<<endl;//Must with const return 0; }