C++ : Unresolved External symbol

acemcmac

Lifer
Mar 31, 2003
13,712
1
0
I passed out a few hours ago working on this project..... as soon as I can get this class working, all I have to do is get its instances into arrays and bind it to a search/sort mechanisim, but alas... I am momentarily lost. Could someone please point out my goof?


-------------------Configuration: project1 - Win32 Debug--------------------
Linking...
project1.obj : error LNK2001: unresolved external symbol "public: void __thiscall Cereal::Set(char,int,int)" (?Set@Cereal@@QAEXDHH@Z)
project1.obj : error LNK2001: unresolved external symbol "public: __thiscall Cereal::Cereal(void)" (??0Cereal@@QAE@XZ)
Debug/project1.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

project1.exe - 3 error(s), 0 warning(s)


//--------------
.h file

class Cereal
{

public :

void Set ( char name , int protein , int calories ) ;
void Write () const;
Cereal (char init_name, int init_protein, int init_Calories ) ; // constructor
Cereal ()a ; // default constructor

private:
char name;
int protein, calories;

};

void Cereal::Write() const
{
cout<< name<<protein<<calories;
}

//--------------
.cpp file

void CerealEntry()
{
Cereal working;
char temp1; int temp2, temp3;
cout<<"Cereal Name:\n";
cin>>temp1;
cout<<"protein:\n";
cin>>temp2;
cout<<"calories:\n";
cin>>temp3;
working.Set(temp1,temp2,temp3);
working.Write;
}
 

Titan

Golden Member
Oct 15, 1999
1,819
0
0
I haven't used VC++ in a while, but I used to, and the compiler message brings back memories.

First, what is this line in your header file?

"Cereal ()a ; // default constructor "

What the heck is that 'a' for? It may eb your error.

Next, i'd say make sure you implement all the member functions you declare in your .h file, particularly if you try to call them.

Gee, now that homework's been assigned, we're getting flooded with other people's work here. Check your compiler and linker error codes for visual studio over at the MSDN and they will be able to give you a better explanation of the problem.
 

acemcmac

Lifer
Mar 31, 2003
13,712
1
0
that "()a" is a typo.... is not in my code.... I have no idea how it ended up like that in the post.

sorry for wasting your time "flooding you with my homework"

It's not like I asked you to do it, I just asked if you might not mind pointing out where I fvcked up.... ATOT is the next best thing to the prof...
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
It you define a non default constructor, you MUST also have a constructor.

I do not see either constructor in your .cpp file.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Unresolved external symbol means that it found a prototype/declaration for the symbol name ... in this case the constructors, but it can't find an implementation of the functions to link to. Compiling goes fine because the compiler only cares that you have the prototype available. So where is your implementation of those constructors?
 

acemcmac

Lifer
Mar 31, 2003
13,712
1
0
oh, im just retarded... my code is a giant swamp of the results of my bssing my way through the cirriculum... I've been up for the last 14 hours flying solo through stuff I should have spent the last year learning....

seems like a stupid question at this point... but is there an industry standard string.h file? the prof didnt specify one and I just realized that I was missing the library.... lol.... I had been using char to take its place until now :)
 

acemcmac

Lifer
Mar 31, 2003
13,712
1
0
the only other people in my degree who can honestly say that they hate programming are long gone... for someone who hates programming with all his being, there is no reason at all why I should have been able to make it this far :beer:
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Uhm ... sounds like you're having a bad day ... get some sleep!
Anyway, yes ... <string.h> is a standard file. Might be deprecated to just <string> on some compilers?
 

acemcmac

Lifer
Mar 31, 2003
13,712
1
0
i dunno.... im on visual studio 6 and I've never had a problem with .h'es before.... man this is weird

none of my strings will load in my cpp
 

acemcmac

Lifer
Mar 31, 2003
13,712
1
0
C:\Documents and Settings\Administrator\Desktop\csc240\project1\project1.cpp(26) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocat

woah... <stoner voice>. im confused....
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Most string functions goes from right to left <<.

Take a close look at your code. The >> may be attempting to shift a string.
The string class may not be setup to support that function.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Originally posted by: acemcmac
well... yea.... string text; cin>>text; whats the problem?

No problem there. I was just pointing out a potential error.

Check that you have <iosteam>

 

Titan

Golden Member
Oct 15, 1999
1,819
0
0
Originally posted by: EagleKeeper
Originally posted by: acemcmac
well... yea.... string text; cin>>text; whats the problem?

No problem there. I was just pointing out a potential error.

Check that you have <iosteam>

Judging by the thread, the problem could be you included <string.h> and not <string>, you also may need <iostream> for cin and cout. The .h files are legacy C headers, the ones without the .h are new C++ ones, and can be quite different. <iostream> is a different header than <iostream.h>., Try just using <string>, also if you use any headers without .h , after you include, you must say "using namespace std;" globally for them to work.