当前位置: 首页>>代码示例>>C++>>正文


C++ SpreadsheetCell::set方法代码示例

本文整理汇总了C++中SpreadsheetCell::set方法的典型用法代码示例。如果您正苦于以下问题:C++ SpreadsheetCell::set方法的具体用法?C++ SpreadsheetCell::set怎么用?C++ SpreadsheetCell::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SpreadsheetCell的用法示例。


在下文中一共展示了SpreadsheetCell::set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: invalid_argument

SpreadsheetCell operator/(const SpreadsheetCell& lhs, const SpreadsheetCell& rhs)
{
	if (rhs.mValue == 0)
		throw invalid_argument("Divide by zero.");
	SpreadsheetCell newCell;
	newCell.set(lhs.mValue / rhs.mValue); // call set to update mValue and mString
	return newCell;
}
开发者ID:JianboTang,项目名称:Professional_CPP,代码行数:8,代码来源:SpreadsheetCell.cpp

示例2:

SpreadsheetCell operator*(const SpreadsheetCell& lhs, const SpreadsheetCell& rhs)
{
	SpreadsheetCell newCell;
	newCell.set(lhs.mValue * rhs.mValue); // call set to update mValue and mString
	return newCell;
}
开发者ID:JianboTang,项目名称:Professional_CPP,代码行数:6,代码来源:SpreadsheetCell.cpp

示例3: main

int main()
{
  // On the stack (destroyed when out of scope)
  SpreadsheetCell stackCell, stackCell2; // Omit parentheses for the default constructor
  stackCell.set(6);
  stackCell2.set("3.2");
  cout << "stack cell 1: " << stackCell.getValue() << endl;
  cout << "stack cell 2: " << stackCell2.getValue() << endl;
  // Constructor on the stack
  SpreadsheetCell stackCell3(4.2), stackCell4(9.2);
  cout << "stack cell 3: " << stackCell3.getValue() << endl;
  cout << "stack cell 4: " << stackCell4.getValue() << endl;
  // On the heap
  SpreadsheetCell* heapCell = new SpreadsheetCell();
  heapCell->set(3.7);
  cout << "heap cell 1: " << heapCell->getValue() << endl;
  delete heapCell;
  heapCell = nullptr;
  // Constructor on the heap
  auto heapCell2 = new SpreadsheetCell(44);
  cout << "heap cell 2: " << heapCell2->getValue() << endl;
  delete heapCell2;
  heapCell2 = nullptr;
  // Smart pointers for the heap
  auto smartCell = make_unique<SpreadsheetCell>();
  smartCell->set(3.14159);
  cout << "smart cell 1: " << smartCell->getValue() << endl;
  // Constructor with for pointer to the heap
  auto smartCell2 = make_unique<SpreadsheetCell>(42);
  cout << "smart cell 2: " << smartCell2->getValue() << endl;
  // Manual heap delayed instantiation
  SpreadsheetCell* heapCell3 = nullptr;
  heapCell3 = new SpreadsheetCell(55);
  cout << "heap cell 3: " << heapCell3->getValue() << endl;
  delete heapCell3;
  heapCell3 = nullptr;
  // Array instantiation requires a default constructor (as to STL collections)
  const int size = 3;
  SpreadsheetCell cells[3];
  SpreadsheetCell* moreCells = new SpreadsheetCell[10]; // HEAP!
  // Stack arrays can use an initializer for non-default constructors
  SpreadsheetCell stackCells[3] = {
    SpreadsheetCell(3),
    SpreadsheetCell(4),
    SpreadsheetCell(5)
  };
  for (int i = 0; i < size; i++) {
    cout << "arr cell " << i << ": " << cells[i].getValue() << endl;
    cout << "heap arr cell " << i << ": " << moreCells[i].getValue() << endl;
    cout << "stack arr cell " << i << ": " << stackCells[i].getValue() << endl;
  }
  delete[] moreCells; // CLEAN THE HEAP!
  moreCells = nullptr;
  // Copy
  auto copyCell = SpreadsheetCell(stackCell);
  cout << "copy cell: " << copyCell.getValue() << endl;
  // Initializer-List Constructor
  // EvenSequence p1 = {1.0, 2.0, 3.0, 4.0, 5.5, 7.7}; // or
  EvenSequence p1 {1.0, 2.0, 3.0, 4.0, 5.5, 7.7};
  p1.dump();
  try {
    EvenSequence p2 = {1.0, 2.0, 3.0};
  } catch (const invalid_argument& err) {
    cout << err.what() << endl;
  }
  // std initializer list
  vector<string> myVec {"Hello", "World"};
  for (auto value : myVec) {
    cout << value << endl;
  }
  // Done
  return 0;
}
开发者ID:knpwrs,项目名称:Learning-CPlusPlus,代码行数:73,代码来源:main.cpp


注:本文中的SpreadsheetCell::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。