当我尝试并编译一个示例来自文本C ++如何通过Deitel编程时,我得到一个链接错误 [英] I Get A Linking Error When I Try And Compile An Example From The Text C++ How To Program By Deitel

查看:70
本文介绍了当我尝试并编译一个示例来自文本C ++如何通过Deitel编程时,我得到一个链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个文件,一个是接口,主文件和头文件。我正在使用visual studio 2012 express。以下是代码:



I have three files, one is an interface, main file and the header file. I am using visual studio 2012 express. Below is the code:

// Exercise 3.11 Solution: ex03_11.cpp
// Test program for modified GradeBook class.
#include <iostream>
#include "GradeBook.h"
using namespace std;

// function main begins program execution
int main()
{
   // create a GradeBook object; pass a course name and instructor name
   GradeBook gradeBook( 
      "CS101 Introduction to C++ Programming", "Professor Smith" );

   // display initial value of instructorName of GradeBook object
   cout << "gradeBook instructor name is: " 
      << gradeBook.getInstructorName() << "\n\n"; 

   // modify the instructorName using set function
   gradeBook.setInstructorName( "Assistant Professor Bates" );

   // display new value of instructorName
   cout << "new gradeBook instructor name is: " 
      << gradeBook.getInstructorName() << "\n\n";

   // display welcome message and instructor's name
   gradeBook.displayMessage(); 
} // end main







// Exercise 3.11 Solution: GradeBook.cpp
// Member-function definitions for class GradeBook.
#include <iostream>
#include "GradeBook.h"
using namespace std;

// constructor initializes courseName and instructorName 
// with strings supplied as arguments
GradeBook::GradeBook( string course, string instructor )
{
   setCourseName( course ); // initializes courseName
   setInstructorName( instructor ); // initialiZes instructorName
} // end GradeBook constructor

// function to set the course name
void GradeBook::setCourseName( string name )
{
   courseName = name; // store the course name
} // end function setCourseName

// function to retrieve the course name
string GradeBook::getCourseName()
{
   return courseName;
} // end function getCourseName

// function to set the instructor name
void GradeBook::setInstructorName( string name )
{
   instructorName = name; // store the instructor name
} // end function setInstructorName

// function to retrieve the instructor name
string GradeBook::getInstructorName()
{
   return instructorName;
} // end function getInstructorName

// display a welcome message and the instructor's name
void GradeBook::displayMessage()
{
   // display a welcome message containing the course name
   cout << "Welcome to the grade book for\n" << getCourseName() << "!" 
      << endl;

   // display the instructor's name
   cout << "This course is presented by: " << getInstructorName() << endl;
} // end function displayMessage







/**************************************************************************
 * (C) Copyright 1992-2010 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 **************************************************************************/






// Exercise 3.11 Solution: GradeBook.h
// Definition of GradeBook class that stores an instructor's name.
#include <string> // program uses C++ standard string class
using namespace std;

// GradeBook class definition
class GradeBook
{
public:
   // constructor initializes course name and instructor name
   GradeBook( string, string );
   void setCourseName( string ); // function to set the course name
   string getCourseName(); // function to retrieve the course name
   void setInstructorName( string ); // function to set instructor name
   string getInstructorName(); // function to retrieve instructor name
   void displayMessage(); // display welcome message and instructor name
private:
   string courseName; // course name for this GradeBook
   string instructorName; // instructor name for this GradeBook
}; // end class GradeBook  



/**************************************************************************
 * (C) Copyright 1992-2010 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 **************************************************************************/   



我得到以下错误:


I get the following errors:

Error	1	error LNK2019: unresolved external symbol "public: __thiscall GradeBook::GradeBook(class std::basic_string<char,struct>,class std::allocator<char> >,class std::basic_string<char,struct>,class std::allocator<char> >)" (??0GradeBook@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) referenced in function _wmain	c:\Users\Leetop\documents\visual studio 2012\Projects\ex311\ex311\ex311.obj	ex311



Error	2	error LNK2019: unresolved external symbol "public: void __thiscall GradeBook::setInstructorName(class std::basic_string<char,struct>,class std::allocator<char> >)" (?setInstructorName@GradeBook@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _wmain	c:\Users\Leetop\documents\visual studio 2012\Projects\ex311\ex311\ex311.obj	ex311


Error	3	error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct>,class std::allocator<char> > __thiscall GradeBook::getInstructorName(void)" (?getInstructorName@GradeBook@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _wmain	c:\Users\Leetop\documents\visual studio 2012\Projects\ex311\ex311\ex311.obj	ex311


Error	4	error LNK2019: unresolved external symbol "public: void __thiscall GradeBook::displayMessage(void)" (?displayMessage@GradeBook@@QAEXXZ) referenced in function _wmain	c:\Users\Leetop\documents\visual studio 2012\Projects\ex311\ex311\ex311.obj	ex311



Error	5	error LNK1120: 4 unresolved externals	c:\users\leetop\documents\visual studio 2012\Projects\ex311\Debug\ex311.exe	1	1	ex311

推荐答案

basic_string @ DU?
basic_string@DU?


char_traits @ D @ std @@ V?
char_traits@D@std@@V?


allocator @ D @ 2 @@ std @@ 0 @ Z)引用在函数_wmain c:\ Users \ Leetop \documents\visual studio 2012 \Projects\ex311 \ex311 \ ex311.obj ex311



错误2错误LNK2019:未解析的外部符号public:void __thiscall GradeBook :: setInstructorName(class std :: basic_string< char,struct> ;, class std :: allocator< char> >)(?setInstructorName @ GradeBook @@ QAEXV?
allocator@D@2@@std@@0@Z) referenced in function _wmain c:\Users\Leetop\documents\visual studio 2012\Projects\ex311\ex311\ex311.obj ex311 Error 2 error LNK2019: unresolved external symbol "public: void __thiscall GradeBook::setInstructorName(class std::basic_string<char,struct>,class std::allocator<char> >)" (?setInstructorName@GradeBook@@QAEXV?


这篇关于当我尝试并编译一个示例来自文本C ++如何通过Deitel编程时,我得到一个链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆