![]() |
|
#1
|
|||
|
|||
Link ErrorsHi,
I am getting link errors when building an application. My code and the link errors are below. //stocktank.h CPP / C++ / C Code:
//driver.cpp CPP / C++ / C Code:
//stocktank.cpp CPP / C++ / C Code:
The link errors are: --------------------Configuration: BrinegarP3 - Win32 Debug-------------------- Linking... driver.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall StockTank::GetTankData(void)" (?GetTankData@StockTank@@QAE?AV?$basic_string@DU?$ char_t raits@D@std@@V?$allocator@D@2@@std@@XZ) stocktank.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall StockTank::GetTankData(void)" (?GetTankData@StockTank@@QAE?AV?$basic_string@DU?$ cha r_traits@D@std@@V?$allocator@D@2@@std@@XZ) Debug/BrinegarP3.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. BrinegarP3.exe - 3 error(s), 0 warning(s) What does this mean? |
|
#2
|
||||
|
||||
Re: Link ErrorsThe problem is in the GetTankData() function. I would guess that the problem is you are not initializing the string data.
You might consider using a stringstream there. That way you can use the << operator to concatonate data on it, just like cout. You should consider using an enumerated typedef for the tank shape, like this: In the header file: CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: Link ErrorsOkay, I see what you mean. But the reason I had everything in the GetTankData() function remarked is that I kept getting compile errors stating that the variables were undefined. I don't understand why, I thought that any public function of the class should be able to see the private data of the class. But when I assign the data variable I get:
CPP / C++ / C Code:
--------------------Configuration: BrinegarP3 - Win32 Debug-------------------- Compiling... stocktank.cpp C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP3\stocktank.cpp(125) : error C2065: 'shape' : undeclared identifier Error executing cl.exe. stocktank.obj - 1 error(s), 0 warning(s The specifications of the program states not to use enum and we haven't gone over it in class yet, although it looks to be easier. Also, when I assign data a value, like above, I still get the link errors. |
|
#4
|
||||
|
||||
Re: Link ErrorsYou're missing the scope operator.
CPP / C++ / C Code:
Without it the compiler doesn't know that GetTankData is a member function of the StockTank class. |
|
#5
|
|||
|
|||
Re: Link ErrorsCool...thank you!
|
|
#6
|
|||
|
|||
Re: Link ErrorsI'm pretty close to having everything working with this program but have a question regarding stringstream.
I'm utilizing this in my program, but one calculated variable I have (totcapgal) in the string StockTank::GetTankData() is displaying on the screen as -1.07374e+008. I'm using cout.setf(ios::fixed) and cout.precision(2) everywhere I can think of but it doesn't make a difference. Is there a way to use stringstream and format this variable as a fixed number with precision 2? Code is below: //stocktank.cpp CPP / C++ / C Code:
The other files are: //driver.cpp CPP / C++ / C Code:
and //stocktank.h CPP / C++ / C Code:
Thanks again for any help. |
|
#7
|
|||
|
|||
Re: Link ErrorsYou set cout.etc(), but you aren't using cout. You need to set ss.setf(ios::fixed) and ss.precision(2).
|
|
#8
|
||||
|
||||
Re: Link Errors^^beat me to it
Also, there's no point in calling the copy constructor here:CPP / C++ / C Code:
Do this instead: CPP / C++ / C Code:
|
|
#9
|
|||
|
|||
Re: Link ErrorsOkay, I tried that and still get the -1.blah number
I've tried placing it in the conditionals as well. CPP / C++ / C Code:
|
|
#10
|
||||
|
||||
Re: Link ErrorsMy guess is that the variable is not being initialized. Try defining a default constructor. It looks to me like you're trying to do that with the function StockTankCalculator(). Turn that function in to your default contructor, and make sure you initialize all the variables.
|
Recent GIDBlog
Observations of Iraq by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Code Snipet For Doubly Linked List | Danny | C Programming Language | 8 | 19-Feb-2008 11:37 |
| High quality link building | spogg | Search Engine Optimization Forum | 7 | 23-Aug-2006 11:41 |
| Compile Errors due to Default Parameters | jdbrine | C++ Forum | 1 | 17-Jun-2006 14:45 |
| Useful Free Link Exchange Program | JC3 | Member Announcements, Advertisements & Offers | 0 | 23-Sep-2005 14:12 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The