| | |
Classes-- stuck in the mire of syntax
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hi,
I am working on a fairly simple project (it will grow more in time as planned) but I am stuck in a spot which I cannot solve yet.
The operation of this prog at this point is:
I consider the action of going to Look.cpp a "function" as declared in Look.h. Maybe this action is not a true function; it does no mathematical operation-- and does it return anything? No, it is void.
I feel very close to solving this but errors keep getting thrown. Perhaps it is just my syntax in the use of objects, referencing, etc?
Any help is greatly appreciated-- thank you in advance.
Arnold L.
Look.h
Look.cpp
Main.cpp
Error Message (VC++ Express 2005)
I am working on a fairly simple project (it will grow more in time as planned) but I am stuck in a spot which I cannot solve yet.
The operation of this prog at this point is:
- Start. Ask user for input choice (only 1 choice available at this point)
- Cin will take user to another screen (another file, Look.cpp) This file will run and request more input.
- This input will run
- End.
I consider the action of going to Look.cpp a "function" as declared in Look.h. Maybe this action is not a true function; it does no mathematical operation-- and does it return anything? No, it is void.
I feel very close to solving this but errors keep getting thrown. Perhaps it is just my syntax in the use of objects, referencing, etc?
Any help is greatly appreciated-- thank you in advance.
Arnold L.

Look.h
C++ Syntax (Toggle Plain Text)
class Look { public: float shipPos ; float satPos; float interior; void printShipPos(); // new function declaration Look(); ~Look(); };
Look.cpp
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "Look.h" using namespace std; void Look::printShipPos() //.h function set here, refers to class // Look via "::" { cin >> shipPos; // this shipPos is the Look class member variable if (shipPos <= 3.80) { std::cout << "French Polynesia [Out of Transmission Range]"<< endl; } else if (shipPos <= 7.60) { std::cout << "Maui, Hawaii [Out of Transmission Range]"<< endl; } else if (shipPos <= 11.40) { std::cout << "Pacific Ocean (open waters) [Out of Transmission Range] 4320 miles from Tampa, Florida"<< endl; } else if ((shipPos >= 15.20) && (shipPos < 19.00)) { std::cout << "Pacific Ocean (open waters) [In Transmission Range] 3240 miles from Tampa, Florida"<< endl; } else if ((shipPos >= 19.00) && (shipPos < 22.80)){ std::cout << "La Paz, Baja, Mexico [In Transmission Range]"<< endl; } else if ((shipPos >= 22.80) && (shipPos < 26.60)){ std::cout << "Gulf of Mexico [In Transmission Range]"<< endl; } else if ((shipPos >= 26.60) && (shipPos < 30.40)){ std::cout << "Tampa, Florida [In Transmission Range]"<< endl; } else if ((shipPos >= 30.40) && (shipPos < 34.20)){ std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 4320 miles from Lisbon, Portugal"<< endl; } else if ((shipPos >= 34.20) && (shipPos < 38.00)){ std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 3240 miles from Lisbon, Portugal"<< endl; } else if (shipPos <= 38.00) { std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 2160 miles from Lisbon, Portugal"<< endl; } else if (shipPos <= 41.80) { std::cout << "Canary Islands [Out of Transmission Range]"<< endl; } else if (shipPos <= 45.60) { std::cout << "Lisbon, Portugal [Out of Transmission Range]"<< endl; } else if (shipPos <= 49.40) { std::cout << "Tripoli, Libya [Out of Transmission Range]"<< endl; } else if (shipPos <= 53.20) { std::cout << "Baghdad, Iraq [Out of Transmission Range]"<< endl; } else if (shipPos <= 57.00) { std::cout << "Eastern Iran [Out of Transmission Range]"<< endl; } else if (shipPos <= 60.80) { std::cout << "Central Tajikistan [Out of Transmission Range]"<< endl; } else if (shipPos <= 64.60) { std::cout << "Kathmandu, Nepal [Out of Transmission Range]"<< endl; } else if (shipPos <= 68.40) { std::cout << "Hanoi, Vietnam [Out of Transmission Range]"<< endl; } else if (shipPos <= 72.20) { std::cout << "Hong Kong, China [Out of Transmission Range]"<< endl; } else if (shipPos <= 76.00) { std::cout << "Pacific (open waters) [Out of Transmission Range] 5400 miles from French Polynesia"<< endl; } else if (shipPos <= 79.80) { std::cout << "Pacific (open waters) [Out of Transmission Range] 4320 miles from French Polynesia"<< endl; } else if (shipPos <= 83.60) { std::cout << "Pacific (open waters) [Out of Transmission Range] 3240 miles from French Polynesia"<< endl; } else if (shipPos <= 87.40) { std::cout << "Pacific (open waters) [Out of Transmission Range] 2160 miles from French Polynesia"<< endl; } else{ std::cout << "Pacific (open waters) [Out of Transmission Range] 1080 miles from French Polynesia"<< endl; } return; } //----------------------------------------------- //float satPos; //function 2 - view of 5 satellites //{ //cin >> satPos; //float interior; //function 3 - view of station interior //{ //cin >> interior;
Main.cpp
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "Look.h" using namespace std; int choice; int main() { std::cout << "________________________________"<< endl; std::cout << ""<< endl; std::cout << "Welcome to Platform XYZ-- Please Enter a Number:"<< endl; std::cout << ""<< endl; std::cout << "[1]Check Location for Transmission to Base"<< endl; std::cout << "[2]Stub"<< endl; std::cout << ""<< endl; std::cout << "________________________________"<< endl; cin >> choice; Look look1; //** ERROR? if(choice == 1){ look1.printShipPos(); //** ERROR? } else { std::cout << "OTHER! chosen (stub)"<< endl; } system("PAUSE"); return 0; }
Error Message (VC++ Express 2005)
C++ Syntax (Toggle Plain Text)
Compiling... main.cpp Linking... main.obj : error LNK2019: unresolved external symbol "public: __thiscall Look::~Look(void)" (??1Look@@QAE@XZ) referenced in function _main main.obj : error LNK2019: unresolved external symbol "public: __thiscall Look::Look(void)" (??0Look@@QAE@XZ) referenced in function _main C:\Documents and Settings\RockStar\Desktop\Space_Station\spaceStation\Debug\spaceStation.exe : fatal error LNK1120: 2 unresolved externals Build log was saved at "file://c:\Documents and Settings\RockStar\Desktop\Space_Station\spaceStation\spaceStation\Debug\BuildLog.htm" spaceStation - 3 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited by Ancient Dragon; Nov 1st, 2006 at 9:38 pm.
Okay, I will just like you to try out one thing if possible by you.
Create a new console C++ project in VS 2005. Create three blank files in it: Main.cpp, Look.cpp and Look.h
Copy and paste the contents of the original files into these files, check to see if all the new files created are in the same folder and same view.
I cant tell you the specifics of VS 2005 since its currently not installed on my computer .
Create a new console C++ project in VS 2005. Create three blank files in it: Main.cpp, Look.cpp and Look.h
Copy and paste the contents of the original files into these files, check to see if all the new files created are in the same folder and same view.
I cant tell you the specifics of VS 2005 since its currently not installed on my computer .
I don't accept change; I don't deserve to live.
~s.o.s~:
TY for your reply.
I did as you suggested. All files are in the same project file.
I receive different errors now.
I do not know what to make of this: I have never knowingly used #include "stdafx.h" before;when I make this new project, files named this (#include "stdafx.h" ) were added, but I simply got rid of them and created a new .h file (Look.h) and two .cpp files (Look.cpp, Main.cpp) then cut-and-pasted the code in question.
I do not know what the error refers to exactly; I looked it up and saw it to be a standard include library (?), so I just added it to the other "include" files on each .cpp file.
Please let me know what you think if you get the chance.
Thanks alot,
Regards,
Arnold L.
TY for your reply.
I did as you suggested. All files are in the same project file.
I receive different errors now.
C++ Syntax (Toggle Plain Text)
Compiling... Look.cpp : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? Main.cpp : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? Generating Code... floodland - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I do not know what the error refers to exactly; I looked it up and saw it to be a standard include library (?), so I just added it to the other "include" files on each .cpp file.
Please let me know what you think if you get the chance.
Thanks alot,

Regards,
Arnold L.
Last edited by Ancient Dragon; Nov 1st, 2006 at 9:49 pm.
Hi:
I made some adjustments to the compiler; I turned off the "precompiled headers" option (suggested on MSDN) and ran the build-- same, old error from before :
Not sure what this means exactly. Will keep working it.
I made some adjustments to the compiler; I turned off the "precompiled headers" option (suggested on MSDN) and ran the build-- same, old error from before :
C++ Syntax (Toggle Plain Text)
------ Build started: Project: floodland, Configuration: Debug Win32 ------ Compiling... Look.cpp Main.cpp Generating Code... Compiling manifest to resources... Linking... Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Look::~Look(void)" (??1Look@@QAE@XZ) referenced in function _main Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Look::Look(void)" (??0Look@@QAE@XZ) referenced in function _main floodland.exe : fatal error LNK1120: 2 unresolved externals floodland - 3 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited by Ancient Dragon; Nov 1st, 2006 at 9:36 pm.
The reason you're getting those errors is because in your header file you defined
The linker looks for the function code, can't find it, and spits out that error.
Look::Look() and Look::~Look, and neglected to implement them in look.cpp.The linker looks for the function code, can't find it, and spits out that error.
Last edited by John A; Oct 31st, 2006 at 10:12 pm.
"Technological progress is like an axe in the hands of a pathological criminal."
joeprogrammer:
TY for your reply. I appreciate you clarifying this. I am a bit confused at this point with classes in general; I have been working at this one area of the code for some time now and cannot get it to run. What you pointed out makes much better sense to me now. I am having trouble figuring out how to implement this in the Look.cpp file, though. The syntax is throwing me and all I keep getting is errors.
Look.cpp
Thanks,
Arnold L.
TY for your reply. I appreciate you clarifying this. I am a bit confused at this point with classes in general; I have been working at this one area of the code for some time now and cannot get it to run. What you pointed out makes much better sense to me now. I am having trouble figuring out how to implement this in the Look.cpp file, though. The syntax is throwing me and all I keep getting is errors.
Look.cpp
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "Look.h" using namespace std; void Look::printShipPos() //.h function set here, refers to class // Look via "::" { cin >> shipPos; // this shipPos is the Look class member variable if (shipPos <= 3.80) { std::cout << "French Polynesia [Out of Transmission Range]"<< endl; } else if (shipPos <= 7.60) { std::cout << "Maui, Hawaii [Out of Transmission Range]"<< endl; } else if (shipPos <= 11.40) { std::cout << "Pacific Ocean (open waters) [Out of Transmission Range] 4320 miles from Tampa, Florida"<< endl; } else if ((shipPos >= 15.20) && (shipPos < 19.00)) { std::cout << "Pacific Ocean (open waters) [In Transmission Range] 3240 miles from Tampa, Florida"<< endl; } else if ((shipPos >= 19.00) && (shipPos < 22.80)){ std::cout << "La Paz, Baja, Mexico [In Transmission Range]"<< endl; } else if ((shipPos >= 22.80) && (shipPos < 26.60)){ std::cout << "Gulf of Mexico [In Transmission Range]"<< endl; } else if ((shipPos >= 26.60) && (shipPos < 30.40)){ std::cout << "Tampa, Florida [In Transmission Range]"<< endl; } else if ((shipPos >= 30.40) && (shipPos < 34.20)){ std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 4320 miles from Lisbon, Portugal"<< endl; } else if ((shipPos >= 34.20) && (shipPos < 38.00)){ std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 3240 miles from Lisbon, Portugal"<< endl; } else if (shipPos <= 38.00) { std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 2160 miles from Lisbon, Portugal"<< endl; } else if (shipPos <= 41.80) { std::cout << "Canary Islands [Out of Transmission Range]"<< endl; } else if (shipPos <= 45.60) { std::cout << "Lisbon, Portugal [Out of Transmission Range]"<< endl; } else if (shipPos <= 49.40) { std::cout << "Tripoli, Libya [Out of Transmission Range]"<< endl; } else if (shipPos <= 53.20) { std::cout << "Baghdad, Iraq [Out of Transmission Range]"<< endl; } else if (shipPos <= 57.00) { std::cout << "Eastern Iran [Out of Transmission Range]"<< endl; } else if (shipPos <= 60.80) { std::cout << "Central Tajikistan [Out of Transmission Range]"<< endl; } else if (shipPos <= 64.60) { std::cout << "Kathmandu, Nepal [Out of Transmission Range]"<< endl; } else if (shipPos <= 68.40) { std::cout << "Hanoi, Vietnam [Out of Transmission Range]"<< endl; } else if (shipPos <= 72.20) { std::cout << "Hong Kong, China [Out of Transmission Range]"<< endl; } else if (shipPos <= 76.00) { std::cout << "Pacific (open waters) [Out of Transmission Range] 5400 miles from French Polynesia"<< endl; } else if (shipPos <= 79.80) { std::cout << "Pacific (open waters) [Out of Transmission Range] 4320 miles from French Polynesia"<< endl; } else if (shipPos <= 83.60) { std::cout << "Pacific (open waters) [Out of Transmission Range] 3240 miles from French Polynesia"<< endl; } else if (shipPos <= 87.40) { std::cout << "Pacific (open waters) [Out of Transmission Range] 2160 miles from French Polynesia"<< endl; } else{ std::cout << "Pacific (open waters) [Out of Transmission Range] 1080 miles from French Polynesia"<< endl; } return; }
Arnold L.
You have 2 options at this point:
You can choose to remove the constructor and destructor definitions from the class header. Classes are not required to have constructors/destructors.
You can add an implementation of these functions to the .cpp file. In this case, something like this would be all that you'd need:
You can choose to remove the constructor and destructor definitions from the class header. Classes are not required to have constructors/destructors.
You can add an implementation of these functions to the .cpp file. In this case, something like this would be all that you'd need:
c Syntax (Toggle Plain Text)
// look.cpp #include <iostream> #include "Look.h" using namespace std; Look::Look() { } Look::~Look() { } // ...
"Technological progress is like an axe in the hands of a pathological criminal."
joeprogrammer:
Thank-you for your reply. I tried your suggestion, adding
It worked great. All error messages vanquished!
I really apprciate your help.
Arnold L.
Thank-you for your reply. I tried your suggestion, adding
C++ Syntax (Toggle Plain Text)
Look::Look() { } Look::~Look(){ }
It worked great. All error messages vanquished!
I really apprciate your help.
Arnold L.
Last edited by Ancient Dragon; Nov 1st, 2006 at 9:47 pm. Reason: Removed extraneous formatting.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Drag and drop of files between applications?
- Next Thread: Insertion Sort Problem
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






