я получаю эти ошибки:поле «класс» имеет несовместимый «класс»
node.h:12:2: error: 'Student' does not name a typeStudent student;
node.h:17:14: error: 'Student' does not name a typeNode(const Student&);
node.h:20:25: error: 'Student' does not name a type
void setStudent(const Student&);
node.h:21:2: error: 'Student' does not name a type
Student getStudent() const { return student; }
это то, что происходит, когда я удалить включить node.h из student.h
node.cpp:13: first defined here
node.cpp.o: In function `Node::~Node()'
node.cpp:13: multiple definition of `Node::Node()'
node.cpp:13: first defined here
node.cpp.o: In function `Node::~Node()':
node.cpp:17: multiple definition of `Node::Node(Node const&)'
main.cpp.o:node.cpp:17: first defined here
node.cpp.o: In function `Node::~Node()':
node.cpp:17: multiple definition of `Node::Node(Node const&)'
main.cpp.o:C:node.cpp:17: first defined here
node.cpp.o: In function `Node::Node(Student const&)':
node.cpp:25: multiple definition of `Node::Node(Student const&)'
node.cpp:25: first defined here
в узле .h
#pragma once
#ifndef node_h
#define node_h
#include "student.h"
class Node
{
private:
Student student;
Node* nextPtr;
Node* prevPtr;
public:
Node();
Node(const Student&);
Node(const Node&);
virtual ~Node() {}
void setStudent(const Student&);
Student getStudent() const { return student; } //second error here
//linked list needs to be set as a friend
friend class dblinkedlist;
};
#endif
в student.h я не понимаю, почему это не работает должным образом, я попытался изменения кода много раз, но безрезультатно.
#ifndef STUDENT_H
#define STUDENT_H
#include <stdio.h>
#include <string>
#include "node.h"
using namespace std;
class Student
{
private:
string FirstName;
string LastName;
int idNumber;
double Gpa;
public:
//constructors
Student();
Student(string, string, int, double);
//copy construtor
Student(const Student&);
//destructor
virtual ~Student(){}
//set/get for private data
void setidNumber(int i);
int getidNumber() const { return idNumber; }
void setFirstName(string);
string getFirstName(string) const { return FirstName; }
void setLastName(string);
string getLastName(string) const { return LastName; }
void setGpa(double g);
double getGpa(double) const { return Gpa; }
void setStudent(const Student&);
Student getStudent() const { return *this; }
//overloaded assignment
Student operator=(const Student&);
//overloaded <<and>>
friend ostream& operator<<(ostream&, const Student&);
friend istream& operator>>(istream&, Student&);
//overloaded ==
friend bool operator==(const Student&, const Student&);
//make Node class a friend
friend class Node;
};
#endif
Я пробовал некоторые другие методы, пытаясь исправить ошибку, но пришли к выводу, нет, любая помощь очень ценится.
Если вы вперед объявить класс, он может быть использован только в качестве указателя или ссылки. «Студенческий студент» не является ни одним из них, поэтому требуется полное определение «Студент». Я бы предположил, что это в student.h, но вы не включили этот файл. –
Возможный дубликат ошибки [«Поле имеет неполный тип»] (http://stackoverflow.com/questions/12466055/field-has-incomplete-type-error) –
Удалите '#include" node.h "из Student. ч, что должно прояснить ситуацию. Вы можете поместить его в Student.cpp (после включения Student.h), если это необходимо. –