| | |
help with c++ classes
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
pls i will like you to help me with something
i was practising with c++ classes and i created a class interface called GradeBook, you know that i will need a source file to write the details of the implementation of the public functions? so in the source file i included the headeer file "GradeBook.h" then the next line i declared the class' constructor like this GradeBook::GradeBook(param goes here...){....} but the compiler returned an error message that a constructor cannot return a value, what pissed me off was that.... that's how it is written in the textbook i use; it must have been seeing the first GradeBook before the colons as a return type.. i am getting fed up..
i was practising with c++ classes and i created a class interface called GradeBook, you know that i will need a source file to write the details of the implementation of the public functions? so in the source file i included the headeer file "GradeBook.h" then the next line i declared the class' constructor like this GradeBook::GradeBook(param goes here...){....} but the compiler returned an error message that a constructor cannot return a value, what pissed me off was that.... that's how it is written in the textbook i use; it must have been seeing the first GradeBook before the colons as a return type.. i am getting fed up..
sometimes books contain errors. please post the code you are trying to compile so we can help you.
>>i am getting fed up
we all feel that way at times. But don't give up. When you feel really frustrated, walk away for awhile and do something else, like watch a good movie on TV.
>>i am getting fed up
we all feel that way at times. But don't give up. When you feel really frustrated, walk away for awhile and do something else, like watch a good movie on TV.
Last edited by Ancient Dragon; Mar 18th, 2007 at 4:40 pm.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
//class GradeBook's source file
c Syntax (Toggle Plain Text)
#include <iostream> using std::cout; using std::endl; #include "GradeBook.h"// to tell the compiler i am using resources from class GradeBook GradeBook::GradeBook(string name){ setCourseName(name); } void GradeBook::setCourseName(string name){ if(name.length() == 0){ cout<<"\nName was not Entered"; } if((name.length() > 0)&&(name.length() <=25)){ courseName = name; }else if(name.length()>25){ courseName=name.substr(0,25); cout<<"\nName \""<<name<<"\" is more than 25 characters and has been truncated to 25"<<endl; } } string GradeBook::getCourseName(){ return courseName; } void GradeBook::displayMessage(){ cout<<"\nWelcome to the grade book of : "<<getCourseName()<<endl; }
Last edited by Ancient Dragon; Mar 18th, 2007 at 4:51 pm. Reason: add code tags
1. you did not include the header file <string>
2. If you are not declaring
and line 21
alternatively, you can add
2. If you are not declaring
using namespace std: after the includes then you need to declare the namespace at each object instance. For example, line 6 would readGradeBook::GradeBook(std::string name){and line 21
std::string GradeBook::getCourseName(){alternatively, you can add
#using std::string after the header file inclusion. Last edited by Ancient Dragon; Mar 18th, 2007 at 4:59 pm.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
thnx for the reply,
I have included that in the class' interface like this :
// implementation of class grade book's interface
I have tried what you said but i'm still in the rat race
I have included that in the class' interface like this :
// implementation of class grade book's interface
c Syntax (Toggle Plain Text)
#include <string> using std::string; //GradeBook's class definition class GradeBook { public: GradeBook(string); void setCourseName(string); string getCourseName(); void displayMessage(); private: string courseName; }
I have tried what you said but i'm still in the rat race
Last edited by Ancient Dragon; Mar 19th, 2007 at 12:05 am. Reason: add code tags
thnx but this is what i get:
--------------------Configuration: GradeBook - Win32 Debug--------------------
Compiling...
GradeBook.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/GradeBook.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
GradeBook.exe - 2 error(s), 0 warning(s)
pls can you do me a favor?
create the class interface yourself with the idea i have given and see if it works you can omit all the validations in member function setCourseName(), i hope i am not a pain in the ****....
if i am, i am sorry
i just can't proceed until i get this,
--------------------Configuration: GradeBook - Win32 Debug--------------------
Compiling...
GradeBook.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/GradeBook.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
GradeBook.exe - 2 error(s), 0 warning(s)
pls can you do me a favor?
create the class interface yourself with the idea i have given and see if it works you can omit all the validations in member function setCourseName(), i hope i am not a pain in the ****....
if i am, i am sorry
i just can't proceed until i get this,
Last edited by addicted; Mar 19th, 2007 at 12:55 am.
>LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
You haven't defined your main() function. The linker doesn't know where the entry point of the application is.
You haven't defined your main() function. The linker doesn't know where the entry point of the application is.
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
thanx alot,
please could you help me with my program, i have wrote about it in the early pages, go through it...... The error came when i put a semicolon at the end of my class interface, when i try to compile the class' source code, i get that message but when i remove the semicolon it brings back the previous error
please could you help me with my program, i have wrote about it in the early pages, go through it...... The error came when i put a semicolon at the end of my class interface, when i try to compile the class' source code, i get that message but when i remove the semicolon it brings back the previous error
This version compiles without errors. In this version I combined the .h and *.cpp into one *.cpp file for simplicity, but you should keep them separate if you wish. I also added the main() function at the bottom of the code. Hope this helps.
c Syntax (Toggle Plain Text)
#include <iostream> #include <string> using std::cout; using std::endl; using std::string; //GradeBook's class definition class GradeBook { public: GradeBook(string); void setCourseName(string); string getCourseName(); void displayMessage(); private: string courseName; }; //#include "GradeBook.h"// to tell the compiler i am using resources from class GradeBook GradeBook::GradeBook(string name){ setCourseName(name); } void GradeBook::setCourseName(string name){ if(name.length() == 0){ cout<<"\nName was not Entered"; } if((name.length() > 0)&&(name.length() <=25)){ courseName = name; }else if(name.length()>25){ courseName=name.substr(0,25); cout<<"\nName \""<<name<<"\" is more than 25 characters and has been truncated to 25"<<endl; } } string GradeBook::getCourseName(){ return courseName; } void GradeBook::displayMessage(){ cout<<"\nWelcome to the grade book of : "<<getCourseName()<<endl; } int main() { return 0; }
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
![]() |
Similar Threads
- need idea for project using classes and inheritance (C++)
- How do i do chat program using MFC (Microsoft Foundation Classes) and Visual Basic? (Visual Basic 4 / 5 / 6)
- Loading classes from a .jar file (Java)
- Help with Classes (C++)
- Understanding classes (C++)
- Working with objects of different Classes (Java)
- Classes (C++)
- Summer Classes (Geeks' Lounge)
Other Threads in the C++ Forum
- Previous Thread: help with c++ vectors
- Next Thread: error C2664
Views: 2062 | Replies: 17
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return simple sort spoonfeeding stream string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






