main.cpp

来自「一本语言类编程书籍」· C++ 代码 · 共 33 行

CPP
33
字号
// Exercise 11.3 Exercising SharedData - main.cpp
#include "shareddata.h"
#include <iostream>
using std::cout;
using std::endl;

int main() {
  int number = 99;
  long lNumber = 9999999L;
  double value = 1.7320508;
  float pi = 3.142f;
  SharedData shared = { 0.1 };  // Initially a double
  shared.show();

  // Now try all four pointers
  shared.piData = &number;      
  shared.type = pInt;
  shared.show();

  shared.plData = &lNumber;
  shared.type = pLong;
  shared.show();

  shared.pdData = &value;
  shared.type = pDouble;
  shared.show();

  shared.pfData = &pi;
  shared.type = pFloat;
  shared.show();

  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?