다음 코드를 컴파일하려고하면 구문 오류가 발생합니다. 이것은 Assignment 1 CS106L Stanford의 것입니다. 나는 실종 된 캐러지를 찾지 못했습니다. 누구든지이 문제에 대해 도움을 줄 수 있습니까? 내 생각 there're 미안이없는 몇 가지 기본적인 것들,스탠포드 cs106L 할당 1 : 그래프 SimpleGraph.cpp Sintax 오류
cl : Command line warning D9002 : ignoring unknown option '-std=c++11'
SimpleGraph.cpp
..\GraphViz\SimpleGraph.cpp(50) : error C2059: syntax error : '{'
..\GraphViz\SimpleGraph.cpp(50) : error C2143: syntax error : missing ';' before '{'
..\GraphViz\SimpleGraph.cpp(50) : error C2143: syntax error : missing ';' before '}'
..\GraphViz\SimpleGraph.cpp(53) : error C2143: syntax error : missing ',' before ':'
..\GraphViz\SimpleGraph.cpp(53) : error C2530: 'e' : references must be initialized
..\GraphViz\SimpleGraph.cpp(53) : error C2143: syntax error : missing ';' before '{'
..\GraphViz\SimpleGraph.cpp(58) : error C2143: syntax error : missing ',' before ':'
..\GraphViz\SimpleGraph.cpp(58) : error C2530: 'n' : references must be initialized
..\GraphViz\SimpleGraph.cpp(58) : error C2143: syntax error : missing ';' before '{'
..\GraphViz\SimpleGraph.cpp(50) : error C2059: syntax error : '{'
..\GraphViz\SimpleGraph.cpp(50) : error C2143: syntax error : missing ';' before '{'
..\GraphViz\SimpleGraph.cpp(50) : error C2143: syntax error : missing ';' before '}'
#include <iostream>
// Bugfix: Disable C++11 feature macros on Mac/libstdc++ to fool Qt into not using C++11 headers
#ifdef __APPLE__
#undef __cplusplus
#define __cplusplus 200303L
#undef __GXX_EXPERIMENTAL_CXX0X__
#endif
#include <QtGui>
#include <QWidget>
#include <QApplication>
#include <algorithm>
#include <QCoreApplication>
#include <QObject>
#include <QSemaphore>
#include "SimpleGraph.h"
#undef main
MyWidget& MyWidget::getInstance() {
static MyWidget instance;
return instance;
}
/* global semaphore to ensure only one update call at a time.
* Prevents overload of update calls */
QSemaphore semaphore;
void InitGraphVisualizer(SimpleGraph & userGraph) {
MyWidget& g = MyWidget::getInstance();
QObject::connect(&userGraph, SIGNAL(graphUpdated(SimpleGraph)),
&g, SLOT(repaint()));
}
void MyWidget::paintEvent(QPaintEvent *event) {
Q_UNUSED(event);
QPainter painter(this);
if (!userGraph.nodes.empty()) {
SimpleGraph copy;
copy.nodes = userGraph.nodes;
copy.edges = userGraph.edges; auto getX = [](const Node& a, const Node& b) {return a.x < b.x;};
double maxX = std::max_element(copy.nodes.begin(), copy.nodes.end(), getX)->x;
double minX = std::min_element(copy.nodes.begin(), copy.nodes.end(), getX)->x;
auto getY = [](const Node& a, const Node& b) { return a.y < b.y;};
double maxY = std::max_element(copy.nodes.begin(), copy.nodes.end(), getY)->y;
double minY = std::min_element(copy.nodes.begin(), copy.nodes.end(), getY)->y;
auto scale = [maxX, maxY, minX, minY](const Node& a) -> Node {
return {(a.x - minX) * 590/(-minX + maxX) + 5, (a.y - minY) * 590/(-minY + maxY) + 5};};
painter.setBrush(Qt::blue);
std::transform(copy.nodes.begin(), copy.nodes.end(), copy.nodes.begin(), scale);
for (Edge & e : copy.edges) {
Node start = copy.nodes[e.start];
Node end = copy.nodes[e.end];
painter.drawLine(start.x, start.y, end.x, end.y);
}
for (Node & n : copy.nodes) {
painter.drawEllipse(n.x - 5, n.y - 5, 10, 10);
}
}
//last_run = QTime::currentTime();
semaphore.release();
}
class WorkerThread : public QThread {
void run() {
int _userMain();
_userMain();
}
};
int main(int argc, char **argv) {
QApplication app(argc, argv);
MyWidget & myWidget = MyWidget::getInstance();
myWidget.resize(600, 600);
myWidget.show();
qRegisterMetaType<SimpleGraph>(); //allows use of SimpleGraph in signals/slots
WorkerThread x;
x.start();
return app.exec();
}
void SimpleGraph::drawGraph(SimpleGraph &graph) {
if (!semaphore.tryAcquire()) return;
MyWidget& m = MyWidget::getInstance();
m.userGraph.nodes = graph.nodes;
m.userGraph.edges = graph.edges;
emit graphUpdated(graph);
}
void DrawGraph(SimpleGraph& userGraph) {
userGraph.drawGraph(userGraph);
}
'# 다음과 같이 당신은 또한 거기에 자동차를 사용할 수 있습니다 undef main' 뭐라고? – PaulMcKenzie
제목에 sintax 오류가 있습니다. – Casey
@PaulMcKenzie : 그와 같은 코드에서 C++ 11 기능을 수동으로 비활성화하는 것과 관련하여 엄청난 해킹처럼 보입니다. ;) – lpapp