Thread: Lnk1120

  1. #1
    Registered User
    Join Date
    Jul 2013

    Post Lnk1120

    // streams.cpp : Defines the entry point for the console application.
    #include "stdafx.h"
    #include <iostream> 
    #include <fstream>
    using namespace std;
    class Student 
        int number; 
        char name[50]; 
        float gpa; 
        Student (int n,const char *s, float g); 
        void save(ofstream& of); 
        void load(ifstream& inf); 
    int main() 
      Student me(11321, "Myself", 4.3); 
      ofstream myfile; 
      ifstream myf;"silly.txt"); 
      return 0; 
    void Student::save(ofstream& of) 
      of.write((char*)&number, sizeof(number)); 
      of.write((char*)name, sizeof(name)); 
      of.write((char*)&gpa, sizeof(gpa)); 
    void Student::load(ifstream& inf) 
    {*)&number, sizeof(number));*)name, sizeof(name));*)&gpa, sizeof(gpa)); 
    On compilation it gives:
    1>streams.obj : error LNK2019: unresolved external symbol "public: __thiscall Student::Student(int,char const *,float)" (??0Student@@QAE@HPBDM@Z) referenced in function _main
    1>c:\users\javed\documents\visual studio 2010\Projects\streams\Debug\streams.exe : fatal error LNK1120: 1 unresolved externals
    Although i followed what is suggested here:
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > Student (int n,const char *s, float g);
    You also need to implement this constructor as well.

    As in
    Student::Student (int n,const char *s, float g) {
      // do something
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    You shouldn't use char arrays. Use std::string. Otherwise you are in for a world of hurt (e.g. buffer overflow possibility, etc).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error LNK1120: 1 unresolved externals
    By ncode in forum C Programming
    Replies: 2
    Last Post: 08-01-2011, 11:21 PM
  2. LNK1120 error
    By Shalmander in forum C++ Programming
    Replies: 1
    Last Post: 08-11-2010, 09:21 AM
  3. fatal error LNK1120: 2 unresolved externals
    By SgtPooki in forum C++ Programming
    Replies: 10
    Last Post: 08-09-2010, 07:28 AM
  4. LNK2019 and LNK1120 Errors?
    By clegs in forum C++ Programming
    Replies: 8
    Last Post: 11-22-2007, 11:46 AM
  5. error LNK1120 & LNK2001:
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 03-10-2004, 09:04 AM