Lỗi thiếu kiểu trả về trong visual studio


Đây là đoạn code mà mình chạy được trên Dev C++ nhưng lại gặp lỗi khi chạy trên visual studio. Mấy bác giúp mình sửa lại với
Code:

#include<iostream>
#include<string>
using namespace std;
class nhanvien
{
private:
	string hoten;
	int tuoi;
	double luong;
public:
	nhanvien()
	{
		hoten = "";
		tuoi = 0;
		luong = 0;
	}
	setthanhphan()
	{
		fflush(stdin);
		cout << "Nhap ho ten: ";
		getline(cin, hoten);
		cout << "Vao tuoi: ";
		cin >> tuoi;
		cout << "Vao luong: ";
		cin >> luong;
	}
	printthanhphan()
	{
		cout << hoten << endl;
		cout << tuoi << endl;
		cout << luong << endl;
	}
};

int main()
{
	nhanvien emp1, emp2, emp3;
	emp1.setthanhphan();
	emp2.setthanhphan();
	emp3.setthanhphan();
	emp1.printthanhphan();
	emp3.printthanhphan();
	system("pause");
	return 0;
}

Debug:

>------ Build started: Project: 2, Configuration: Debug Win32 ------
1>Source.cpp
1>c:\users\nguye\source\repos\2\2\source.cpp(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\nguye\source\repos\2\2\source.cpp(26): warning C4183: 'setthanhphan': missing return type; assumed to be a member function returning 'int'
1>c:\users\nguye\source\repos\2\2\source.cpp(28): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\nguye\source\repos\2\2\source.cpp(32): warning C4183: 'printthanhphan': missing return type; assumed to be a member function returning 'int'
1>Done building project "2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Thiếu kiểu trả về kìa bạn. :slight_smile:

2 Likes

Chia tay Dev-C++ được rồi đó. Cái lỗi nghiêm trọng mà cũng bỏ qua cho được, Dev-C dở hơi. :v

3 Likes

Vậy thì nên sửa code như thế nào vậy bác ?

Lỗi bảo thiếu thì sửa tất nhiên là phải thêm.

Mà thêm cái gì mới được. :thinking:

Dựa vào kiểu trả về của từng hàm mà thêm thôi. (retrun á).

Nhưng ở trên có return đâu nhỉ.

Vậy thì là void.

Lằng nhằng đủ r. :sweat_smile: Tóm lại là sửa:

  • printthanhphan() :point_right: void printthanhphan().
  • setthanhphan() :point_right: void setthanhphan().
2 Likes

thêm void vô trước printthanhphan() và setthanhphan(), còn nhanvien() là hàm tạo rồi nên không cần void :v:

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?