error LNK2019: 无法解析的外部符号 (C++编程出现问题的解决办法)

今天,练习编程时,照着书本敲代码,居然出现了问题,太诡异了。而且出现的是:error LNK2019: 无法解析的外部符号

这样诡异的问题,着实困扰了我10分钟。然后我找到了解决办法——补充默认不带参数的构造函数的函数体。



######################################

方法如下:

######################################


1.出问题的代码如下


#include "stdafx.h"
#include <iostream>


using namespace std;

class DayofYear
{
public:
	DayofYear(int the_month, int the_day);

	DayofYear();

	void input();

	void output();

	int get_month();

	int get_day();

private:
	void check_date();
	int month;
	int day;
};

bool equal(DayofYear date1, DayofYear date2);

int _tmain(int argc, _TCHAR* argv[])
{
	DayofYear today, bach_birthday(3, 21);
	cout << "Enter today's date: \n";
	today.input();
	cout << "Today's date is ";
	today.output();
	cout << "J. S. Bach's birthday is ";
	bach_birthday.output();
	if ( equal(today, bach_birthday))
	{
		cout << "Happy Birthday Johann Sebastian!\n";
	}
	else
	{
		cout << "Happy Unbirthday Johann Sebastian!\n";

	}

	system("pause");
	return 0;
}

bool equal(DayofYear date1, DayofYear date2)
{
	return ( date1.get_month() == date2.get_month() &&
		date1.get_day() == date2.get_day() );
}

DayofYear::DayofYear(int the_month, int the_day)
	: month(the_month), day(the_day)
{
	check_date();

}

//DayofYear::DayofYear()
//{
//
//}

int DayofYear::get_month()
{
	return month;
}

int DayofYear::get_day()
{
	return day;
}

void DayofYear::input()
{
	cout << "Enter the month as a number: ";
	cin >> month;
	cout << "Enter the day of the month: ";
	cin >> day;
}

void DayofYear::output()
{
	cout << "month = " << month
		<< ", day = " << day << endl;
}


void DayofYear::check_date()
{
	
}


2.解决问题的代码如下,只改了一个地方,就是去掉上面代码的注释

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>


using namespace std;

class DayofYear
{
public:
	DayofYear(int the_month, int the_day);

	DayofYear();

	void input();

	void output();

	int get_month();

	int get_day();

private:
	void check_date();
	int month;
	int day;
};

bool equal(DayofYear date1, DayofYear date2);

int _tmain(int argc, _TCHAR* argv[])
{
	DayofYear today, bach_birthday(3, 21);
	cout << "Enter today's date: \n";
	today.input();
	cout << "Today's date is ";
	today.output();
	cout << "J. S. Bach's birthday is ";
	bach_birthday.output();
	if ( equal(today, bach_birthday))
	{
		cout << "Happy Birthday Johann Sebastian!\n";
	}
	else
	{
		cout << "Happy Unbirthday Johann Sebastian!\n";

	}

	system("pause");
	return 0;
}

bool equal(DayofYear date1, DayofYear date2)
{
	return ( date1.get_month() == date2.get_month() &&
		date1.get_day() == date2.get_day() );
}

DayofYear::DayofYear(int the_month, int the_day)
	: month(the_month), day(the_day)
{
	check_date();

}

DayofYear::DayofYear()//是的,没错,就是这里!!!!!!!!!!!
{

}

int DayofYear::get_month()
{
	return month;
}

int DayofYear::get_day()
{
	return day;
}

void DayofYear::input()
{
	cout << "Enter the month as a number: ";
	cin >> month;
	cout << "Enter the day of the month: ";
	cin >> day;
}

void DayofYear::output()
{
	cout << "month = " << month
		<< ", day = " << day << endl;
}


void DayofYear::check_date()
{
	
}

好了,现在大家知道,怎么解决问题了吧。




-------------------------------------


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值