簡體   English   中英

錯誤LNK2001:無法解析的外部符號_Main

[英]error LNK2001: unresolved external symbol _Main

我這里有些代碼似乎無法正確鏈接。 我已經搜索過,並且有好幾個地方建議它是int main()的問題。 不太確定我的問題是什么。 我是編程新手,並且嘗試了一些不同的方法。 任何幫助將是巨大的!

我有四個文件:Wire.h,Wire.cpp,Gate.h和Gate.cpp。

這是Wire.h

#ifndef WIRE_H
#define WIRE_H

#include <iostream>
#include<vector>
#include<map>
#include<string>
#include "Gate.h"

using namespace std;

class Gate;

class Wire {
public:
    // constructors
    Wire();

    // destructor
    ~Wire();

    //functions
    int getState();
    void setState(int s);

private:
    int State;
    vector<Gate*> Gates;
    vector<int> History;


};

#endif //WIRE_H

這是Wire.cpp:

#include "Wire.h"

#include<iostream>
using namespace std;

int main() {
    cout << "Hello World";
    return 0;
}

Wire::Wire(){
    State = UNKNOWN;
}

Wire::~Wire(){

    for (int i = 0; i < 1/*Gates.size()*/; i++){
        Gates.pop_back();
    }
    for (int i = 0; i < 1/*History.size()*/; i++){
        History.pop_back();
    }
}

int Wire::getState() {
    return State;
}

void Wire::setState(int s) {
    State = s;
}

這是Gate.h:

#ifndef GATE_H
#define GATE_H

#include "Wire.h"

#include <iostream>
#include<vector>
#include<map>
#include<string>

using namespace std;
const int HI = 1;
const int LOW = 0;
const int UNKNOWN = -1;

class Wire;

class Gate {
public:

    // destructor
    ~Gate();

    //functions
    void logic();
    void setType(string);
    void setDelay(int);
    void setAIO(int i, int o); //Only for the NOT gate
    void setBIO(int ain, int bin, int o); //For all gates except for NOT


private:
    string Type;
    Wire* inputA;
    Wire* inputB;
    Wire* output;
    int delay;


};

#endif //GATE_H

這是Gate.cpp

#include "Gate.h"

#include<iostream>
using namespace std;

Gate::Gate(){
    inputA = new Wire();
}

Gate::~Gate(){
    delete inputA;
    delete inputB;
    delete output;
}

void Gate::logic(){
    if (Type == "NOT"){
        if (inputA->getState() == UNKNOWN){
        }
        if (inputA->getState() == HI){
            output->setState(LOW);
        }
        if (inputA->getState() == LOW){
            output->setState(HI);
        }
    }
    if (Type == "AND") {
        if (inputA->getState() == HI && inputB->getState() == HI){
            output->setState(HI);
        }
        else {
            output->setState(LOW);
        }
    }
    if (Type == "OR") {
        if (inputA->getState() == HI || inputB->getState() == HI){
            output->setState(HI);
        }
        else {
            output->setState(LOW);
        }
    }
    if (Type == "XOR"){
        if (inputA->getState() != inputB->getState()){
            output->setState(HI);
        }
        else
        {
            output->setState(LOW);
        }
    }
    if (Type == "NAND"){
        if (inputA->getState() == HI && inputB->getState() == HI){
            output->setState(LOW);
        }
        else{
            output->setState(HI);
        }
    }
    if (Type == "NOR"){
        if (inputA->getState() == LOW && inputB->getState() == LOW){
            output->setState(HI);
        }
        else{
            output->setState(LOW);
        }
    }
    if (Type == "XNOR"){
        if (inputA->getState() == inputB->getState()){
            output->setState(HI);
        }
        else
        {
            output->setState(LOW);
        }
    }
}

void Gate::setType(string t){
    Type = t;
}

void Gate::setDelay(int d){
    delay = d;
}

在c ++中,編譯可執行文件時,編譯器需要知道從哪里開始執行。 為了實現這一點,您需要一個帶有以下簽名的名為main的函數:

int main() { ... }

要么

int main(int argc, char** argv){ ... }

您沒有此功能。 將其添加到您的cpp文件之一。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM