编译错误:找不到标头、类和类接口的任何问题
Errors in compilation: Can't find any problems with headers, classes, and class interfaces
我不理解编译中的错误。我没有发现任何语法问题。
错误:
/dev/shm/ccEF5pIa.o: In function `main':
fig03_13.cc:(.text+0x45): undefined reference to `GradeBook::GradeBook(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
fig03_13.cc:(.text+0x9d): undefined reference to `GradeBook::GradeBook(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
fig03_13.cc:(.text+0xce): undefined reference to `GradeBook::getCourseName()'
fig03_13.cc:(.text+0xe1): undefined reference to `GradeBook::getCourseName()'
collect2: ld returned 1 exit status
GradeBook.cc:21:8: error: prototype for 'std::string GradeBook::displayMessage()' does not match any in class 'GradeBook'
GradeBook.h:15:8: error: candidate is: void GradeBook::displayMessage()
这是成绩册。h
#include <string> // class GradeBook uses C++ standard string class
using namespace std;
// GradeBook class definition
class GradeBook
{
public:
GradeBook(string); // constructor that initializes courseName
void setCourseName(string); // function that sets the course name
string getCourseName(); // function that gets the course name
void displayMessage(); // function that displays a welcome message
private:
string courseName; // course name for this GradeBook
};
成绩册.cc
#include <iostream>
#include "GradeBook.h" // include definition of class GradeBook
using namespace std;
// constructor initializes courseName with string supplied as argument
GradeBook::GradeBook(string name)
{
setCourseName(name); // call set function to initialize courseName
} // end GradeBook constructor
// function to set the course name
void GradeBook::setCourseName(string name)
{
courseName = name; // store the course name in the object
} // end function setCourseName
// function to get the course name
string GradeBook::displayMessage()
{
// call getCourseName to get the courseName
cout << "welcome to the grade book forn" << getCourseName() << "!" << endl;
} // end function displayMessage
图03_13.cc
#include <iostream>
#include "GradeBook.h" // include definition of class GradeBook
using namespace std;
// function main begins program execution
int main() {
// create two GradeBook objects
GradeBook gradeBook1("CS101 Introduction to C++ Programming");
GradeBook gradeBook2("CS102 Data Structures in C++");
// display initial value of courseName for each GradeBook
cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
<< "ngradeBook2 created for course: " << gradeBook2.getCourseName() << endl;
} // end main
定义:字符串成绩册::displayMessage()。
声明:void displayMessage()
您不需要返回字符串。只需保留无效版本即可。
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何在不产生任何垃圾的情况下获得C中的像素
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- Visual C++GC接口如何启用它以及要包含哪个库
- Windows.h与GLFW.h的接口
- C++映射有2个键,这样任何1个键都可以用来获取值
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 模板化接口 - 创建一个泛型模板类以返回任何容器
- 任何挂钩功能的单一接口
- 任何结构接口
- 是否有任何挂钩接口在编译时间内更换功能
- C ++类实现接口,接口具有采用任何实现该接口的类的方法
- 使用 libusb-win32 与 USB 到 DMX512 接口通信,找不到任何端点
- 插件接口设计,用于无偏接口,允许任何编程语言使用它
- 什么是POSIX,任何其他可以取代它的接口标准
- 在德墨忒耳定律和过多的接口重复之间取得平衡的任何指导
- 任何耶普的分段错误!接口调用
- 编译错误:找不到标头、类和类接口的任何问题