У меня есть код здесь, который, похоже, не правильно связан. Я искал, и несколько мест предположили, что это проблема с int main(). Не совсем уверен, в чем моя проблема. Я довольно новичок в программировании, и я попробовал несколько разных вещей. Любая помощь будет замечательной!ошибка LNK2001: неразрешенный внешний символ _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;
}
*** Я искал, и несколько мест предположили, что это проблема с int main() *** Из-за ошибки кажется, что проблема заключается в '_Main' not' _main'. C++ чувствителен к регистру. – drescherjm
'Gate :: Gate()' не определен в определении класса – user4581301
Следите за расточительным использованием 'using namespace std;' Это достаточно опасно для себя и очень плохо в заголовках. – user4581301