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


C++ SpreadsheetCell类代码示例

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


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

示例1: main

int main()
{
  SpreadsheetCell myCell;
  myCell.setValue(6);

  return 0;
}
开发者ID:JianboTang,项目名称:Professional_CPP,代码行数:7,代码来源:SpreadsheetCellTestDefault.cpp

示例2: invalid_argument

SpreadsheetCell operator/(const SpreadsheetCell& lhs, const SpreadsheetCell& rhs)
{
	if (rhs.getValue() == 0) {
		throw invalid_argument("Divide by zero.");
	}
	return SpreadsheetCell(lhs.getValue() / rhs.getValue());
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:7,代码来源:SpreadsheetCell.cpp

示例3: 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

示例4: main

int main()
{
	SpreadsheetCell myCell(4), anotherCell(5);
	SpreadsheetCell aThirdCell = myCell.add(anotherCell);
	cout << aThirdCell.getValue() << endl;

	return 0;
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:8,代码来源:SpreadsheetCellTest.cpp

示例5: main

int main()
{
	SpreadsheetCell* myCellp = new SpreadsheetCell();

	myCellp->setValue(3.7);
	cout << "cell 1: " << myCellp->getValue() <<
		" " << myCellp->getString() << endl;
	delete myCellp;
	myCellp = nullptr;

	return 0;
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:12,代码来源:SpreadsheetCellHeap.cpp

示例6: main

int main()
{
	// Using the default constructor
	SpreadsheetCell myCell;
	myCell.setValue(6);
	cout << "cell 1: " << myCell.getValue() << endl;

	// The next line will crash when compiled with SpreadsheetCellInitListBackward.cpp
	SpreadsheetCell myCell2("6");

	auto smartCellp = make_unique<SpreadsheetCell>();
	// Or with a naked pointer (not recommended)
	SpreadsheetCell* myCellp = new SpreadsheetCell();
	// ... use myCellp
	delete myCellp;
	myCellp = nullptr;

	return 0;
}
开发者ID:JianboTang,项目名称:Professional_CPP,代码行数:19,代码来源:SpreadsheetCellTest.cpp

示例7:

bool operator>(const SpreadsheetCell& lhs, const SpreadsheetCell& rhs)
{
	return (lhs.getValue() > rhs.getValue());
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:4,代码来源:SpreadsheetCell.cpp

示例8: SpreadsheetCell

SpreadsheetCell operator*(const SpreadsheetCell& lhs, const SpreadsheetCell& rhs)
{
	return SpreadsheetCell(lhs.getValue() * rhs.getValue());
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:4,代码来源:SpreadsheetCell.cpp

示例9: printCell

void printCell(const SpreadsheetCell& inCell)
{
	cout << inCell.getString() << endl;
}
开发者ID:JianboTang,项目名称:Professional_CPP,代码行数:4,代码来源:SpreadsheetCell.cpp

示例10:

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

示例11: 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

示例12: SpreadsheetCell

SpreadsheetCell SpreadsheetCell::operator+(const SpreadsheetCell& cell) const
{
	return SpreadsheetCell(getValue() + cell.getValue());
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:4,代码来源:SpreadsheetCell.cpp


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