为什么我的代码不能编译?请帮忙! [英] Why won't my code compile? Please help!

查看:106
本文介绍了为什么我的代码不能编译?请帮忙!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的..所以我需要一些C ++课程的帮助。我一直在网上使用教程来帮助我,但现在我只是被卡住了。我有以下代码:



server.h:



Okay.. so I need some help with my C++ class. I''ve been using tutorials online to help me, but now I''m just plain stuck. I have the following code:

server.h:

#ifndef USER_H
#define USER_H
#include <vector>
#include <iostream>
#include <string>
#include <my_global.h>
#include <mysql.h>
namespace Mainframe
{
class User
{

public:

	Mainframe::User::User(std::string);
	int grabInfo();
};
}
#endif





服务器。 cpp:





server.cpp:

#include "stdafx.h"
#include "server.h"

		MYSQL *conn;

    Mainframe::User::User(std::string id)
	{
	conn = mysql_init(NULL);

	//Connect to the server...
	mysql_real_connect(conn, "localhost", "root", "password", "users", 0, NULL, 0);
	}

	int Mainframe::User::grabInfo()
	{
		return mysql_query(conn, "SELECT * FROM users");
		mysql_close(conn);
	}





现在,您可能已经注意到,我正在使用MySQL C API进行数据库调用。这是我第一次使用它。无论如何,每次我尝试编译时都会收到错误:





Now, as you may have noticed, I am using MySQL C API for database calling. This is my first time using it. Anyway, every time I try to compile I get the error:

error C2512: no appropriate default constructor available





所以我做了一些研究并把它放在头文件中的构造函数之前:





So I did some research and put this before the constructor in my header file:

Mainframe::User::User();





然后我将引用的函数添加到我的cpp file:





I then added the referenced function to my cpp file:

Mainframe::User::User() { }





我编译。默认的构造函数错误消失了,但我只剩下这个了:





And I compile. The default constructor error is gone, but I''m instead left with this:

Error	5	error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function "public: __thiscall Mainframe::User::User(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0User@Mainframe@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)	E:\My Documents\Visual Studio 2010\Projects\LoveBird\MSQLClientTest\server.lib(connect.obj)	MSQLClientTest


Error	8	error LNK2019: unresolved external symbol _mysql_query@8 referenced in function "public: int __thiscall Mainframe::User::grabInfo(void)" (?grabInfo@User@Mainframe@@QAEHXZ)	E:\My Documents\Visual Studio 2010\Projects\LoveBird\MSQLClientTest\server.lib(connect.obj)	MSQLClientTest

Error	6	error LNK2019: unresolved external symbol _mysql_init@4 referenced in function "public: __thiscall Mainframe::User::User(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0User@Mainframe@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)	E:\My Documents\Visual Studio 2010\Projects\LoveBird\MSQLClientTest\server.lib(connect.obj)	MSQLClientTest

Error	7	error LNK2019: unresolved external symbol _mysql_close@4 referenced in function "public: int __thiscall Mainframe::User::grabInfo(void)" (?grabInfo@User@Mainframe@@QAEHXZ)	E:\My Documents\Visual Studio 2010\Projects\LoveBird\MSQLClientTest\server.lib(connect.obj)	MSQLClientTest

Error	9	error LNK1120: 4 unresolved externals	1	E:\My Documents\Visual Studio 2010\Projects\LoveBird\Debug\MSQLClientTest.exe	1	MSQLClientTest





我不知道出了什么问题!请帮助我。我对C ++很陌生并原谅我,如果这样的话是一个愚蠢的问题。提前谢谢。



I have no idea what''s wrong! Please help me. I''m pretty new to C++ and forgive me if this is a stupid question. Thanks in advance.

推荐答案

basic_string @ DU?
basic_string@DU?


char_traits @ D @ std @@ V?
char_traits@D@std@@V?


allocator @ D @ 2 @@ std @@@ Z)E:\ My Documents\Visual Studio 2010 \\ \\ Project \ LoveBird \ MSQLClientTest \server.lib(connect.obj)MSQLClientTest


错误8错误LNK2019:未解析的外部符号_mysql_query @ 8在函数public:int __thiscall中引用Mainframe :: User :: grabInfo(void)(?grabInfo @ User @ Mainframe @@ QAEHXZ)E:\ My Documents\Visual Studio 2010 \Projects\LoveBird\MSQLClientTest\server.lib(connect。 obj)MSQLClientTest

错误6错误LNK2019:未解析的外部符号_mysql_init @ 4在函数public:__thiscall Mainframe :: User :: User中引用(类std :: basic_string< char,struct std :: char_traits< ; char>,类std :: allocator< char> >)(?? 0User @ Mainframe @@ QAE @ V?
allocator@D@2@@std@@@Z) E:\My Documents\Visual Studio 2010\Projects\LoveBird\MSQLClientTest\server.lib(connect.obj) MSQLClientTest Error 8 error LNK2019: unresolved external symbol _mysql_query@8 referenced in function "public: int __thiscall Mainframe::User::grabInfo(void)" (?grabInfo@User@Mainframe@@QAEHXZ) E:\My Documents\Visual Studio 2010\Projects\LoveBird\MSQLClientTest\server.lib(connect.obj) MSQLClientTest Error 6 error LNK2019: unresolved external symbol _mysql_init@4 referenced in function "public: __thiscall Mainframe::User::User(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0User@Mainframe@@QAE@V?


这篇关于为什么我的代码不能编译?请帮忙!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆