-1

My constructor has a green line underneath it saying "function definition not found".

Visual Studio has given me a fix, but I want to know why mine doesn't work.

#pragma once
#include "class_dayType.h"
#include <iostream>
#include <string>
using namespace std;

int main() {
    dayType day;
    string d;

    cout << "Enter day of week: ";
    cin >> d;

    day.set_day(d);
}

#include <iostream>
#include<string>
using namespace std;

class dayType {
public:
    string day;
    dayType();  //constructor with green line

    void set_day(string day_of_week) {
        string day = day_of_week;
    }
};

Visual Studio created this in another file and it worked. What is the difference between this and my constructor?

dayType::dayType()
{
}

Errors:

LNK2019 unresolved external symbol "public: __thiscall dayType::dayType(void)" (??0dayType@@QAE@XZ) referenced in function _main Day_of_Week

LNK1120 1 unresolved externals Day_of_Week

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

1 Answers1

1
dayType(); 

This is not a definition, it's just a declaration. It indicates that a constructor (or any function) will be present somewhere in the code later on.

You would need

dayType() 
{
}

Read more here and here.

Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78