我不习惯使用MinGW和C ++,每当尝试编译我的源文件时,可执行文件似乎什么都不做,即使它应该输出一个简单的“Hello World!”。我已经尝试评论使用import UIKit
class NotesViewController: UIViewController {
var stateController: StateController!
fileprivate var dataSource: FeedDataSource!
@IBOutlet var tableView: UITableView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let reflection = Reflection(title: "Hello", body: "world", author: "Alex", favorite: true, creationDate: Date(), id: UUID())
//stateController.add(reflection)
dataSource = FeedDataSource(notes: stateController.notes)
tableView.dataSource = dataSource
tableView.reloadData()
}
class FeedDataSource: NSObject {
var notes: [Reflection]!
init(notes: [Reflection]) {
self.notes = notes
}
}
extension FeedDataSource: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return notes.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reflectionCell", for: indexPath) as! ReflectionCell
let index = indexPath.row
let note = notes[index]
cell.model = ReflectionCell.Model(data: note)
return cell
}
}
The cell class:
class ReflectionCell: UITableViewCell {
@IBOutlet weak fileprivate var titleLabel: UILabel!
@IBOutlet weak fileprivate var bodyLabel: UILabel!
@IBOutlet weak fileprivate var authorLabel: UILabel!
@IBOutlet weak fileprivate var bookmarkButton: UIButton!
fileprivate var id: UUID!
var model: Model? {
didSet {
guard let model = model else {
return
}
titleLabel.text = model.title
bodyLabel.text = model.body
authorLabel.text = model.author
bookmarkButton.isSelected = model.favorite
id = model.id
}
}
override func awakeFromNib() {
super.awakeFromNib()
bookmarkButton.setImage(#imageLiteral(resourceName: "Bookmark-Highlighted"), for: .selected)
}
}
extension ReflectionCell {
struct Model {
let title: String
let body: String
let author: String
let favorite: Bool
let id: UUID
init(data: Reflection) {
title = data.title
body = data.body
author = data.author
favorite = data.favorite
id = data.id
}
}
}
的行,并输出“Hello World!”很好。
似乎没有做或输出任何内容的源代码:
vector
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
const int LIMIT = 1000000; // one million
int main(int argc, char *argv[])
{
int* arr = new int[LIMIT] {0};
vector<int>* v = new vector<int>();
cout << "Hello World!" << endl;
delete v;
return 0;
}
的源代码注释掉了输出“Hello World!”很好:
vector
两者都编译并运行:
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
const int LIMIT = 1000000; // one million
int main(int argc, char *argv[])
{
int* arr = new int[LIMIT] {0};
// vector<int>* v = new vector<int>();
cout << "Hello World!" << endl;
// delete v;
return 0;
}
编译并运行任何一个都不会产生任何错误消息。请注意,C:\Users\User\my\directory\src> g++ source.cpp -o source.exe -std=c++11
C:\Users\User\my\directory\src> ./source.exe
在两个实例中都保持取消注释。