Hi, I am reading deitel and associates' how to program in C/C++... I followed the code that was written on one of the chapters.. I typed them myself to be acquainted with the structure of right coding and when I compiled it, it went good and the program ran fine... however, crimseon editor (my source editor) returned a somewhat a warning or error.. I don't know...
heres the code I typed. verbatim.
// fig. 3.1 fig03_01.cpp
// Define class GradeBook with a member function that takes a parameter
// Create a Gradebook object and call its member function displayMessage
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string> // program uses C++ standard string class
using std::string;
using std::getline;
// Gradebook class definition
class GradeBook
{
public:
void displayMessage(string courseName) // a function that displays a welcome message to the GradeBook class
{
cout << "Welcome to the Grade Book for\n" << courseName << "!" << endl;
} // end function call displayMessage
}; // end class GradeBook
// function main begins program execution
int main()
{
string nameOfCourse; // string of characters to store the course name
GradeBook myGradeBook; // creates a GradeBook object called myGradeBook
// prompt for the input course name
cout << "Please enter the course name: " << endl;
getline(cin, nameOfCourse); // read a course name with blanks
cout << endl; // output a blank line
// call myGradeBook's displayMessage function
// and pass nameOfCourse as an argument
myGradeBook.displayMessage(nameOfCourse); // call object GradeBook's displayMessage function
return 0; // successful termination
} // end main
then crimson editor returned these results after compiling..
---------- Capture Output ----------
> "C:\Borland\BCC55\bin\bcc32.exe" fig03_03.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
fig03_03.cpp:
Warning W8026 fig03_03.cpp 19: Functions taking class-by-value argument(s) are not expanded inline in function GradeBook::displayMessage(string)
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
> Terminated with exit code 0.
I just want to know what the warning means... is there an error in what I did?
i tried looking for it, but my knowledge is still limited..
It is complaining for the fact that it will have to copy the string object. You should pass it by const reference: void displayMessage( const string &courseName)
That method should also be const as it doesn't modify the class members: void displayMessage( const string &courseName) const
It means what is says.
GradeBook::displayMessage() takes an std::string passed by value, which means a copy of the std::string has to be made. The compiler decided not to inline this function.
Member functions defined inside the class have the inline property implied. If you don't know what this means, don't worry about it.