0

i worked for 4 years on Java. Now im trying to learn C++. I want to create a Teamspeak3-Plugin. First of all i tried to create a MySQL-Connection and i stuck on compiling. I worked with the MySQL-Connector for C++ Version 8.0.20 and Boost for C++(for the connector) Version 1.72.0

It gives me the ErrorCode "C3867" which is saying "non standard syntax use & to create a pointer to member"

I dont know why i am getting this error and especially how to solve it.

Here are my classes:

mysql.h:

#ifndef mysql_H
#define mysql_H
#include <iostream>
#include <string>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

using namespace std;

class mysql
{
public:
    mysql();
    int connect;
    void createTables();
    list<char*> getResult(char* qry);

};


#endif // !mysql_H

mysql.cpp

#include <iostream>
#include <string>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include "mysql.h"

using namespace std;
using namespace sql;

std::string host = "";
std::string port = "";
char* user = "";
char* password = "";
char* database = "";

sql::Driver *driver;
sql::Connection *con;
sql::ResultSet *res;

int connect() {


    try {
        driver = get_driver_instance();
        std::string url = "tcp://" + host + ":" + port;
        con = driver->connect(url, user, password);
        cout << "MySQL connected!";

        con->setSchema(database);
        cout << "Database selected!";
        return 0;
    }
    catch (sql::SQLException err) {
        cout << "ERROR: " << err.what << endl;
    }

}

void createTables() {
    sql::Statement *stmt;
    try {
        stmt = con->createStatement();
        stmt->executeQuery("CREATE TABLE IF NOT EXISTS JellyTest(Name VARCHAR(100), COINS INT)");
        cout << "TableCreating done";
    }
    catch (sql::SQLException err) {
        cout << "ERROR: " << err.what << endl;
    }
}

list<char*> getResult(char* qry) {
    sql::Statement *stmt;
    sql::ResultSet *res;
    list<char*> result;
    try {
        stmt = con->createStatement();
        res = stmt->executeQuery(qry);
        while (res->next) {
            result.assign(res->next);
        }
        return result;
    }
    catch (sql::SQLException err) {
        cout << "ERROR: " << err.what << endl;
    }
}

Thanks for helping and have a nice day. (I hope you are able to understand this text 'cause im from Germany)

  • 1
    Is the error raised for `err.what`? It should be `err.what()`. You also need to be careful about memory leaks and dangling pointers – Alan Birtles Apr 28 '20 at 01:37
  • By "doesn't work" do you mean "crash"? You shouldn't be returning a list of pointers, you need a list (or preferably a vector) of std::string which will properly handle the necessary memory allocation and copying – Alan Birtles Apr 28 '20 at 01:48
  • I solved the problem, but know i have another problem. It turns me this error: https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2019?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev16.query%3FappId%3DDev16IDEF1%26l%3DDE-DE%26k%3Dk(LNK2019)%26rd%3Dtrue&view=vs-2019 With the classes you see above(but fixed the errors) and another class, where i am trying to run the class: https://pastebin.com/7MNa8WAh Just take a look at these lines: 17, 111, 113, 114 – niklas.bzr Apr 28 '20 at 02:08
  • https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – Alan Birtles Apr 28 '20 at 06:48
  • Are you able to tell me how solve exactly my problem? It costs too much to read the hole Question, you sent me above. – niklas.bzr Apr 28 '20 at 17:24
  • not without a [mre] with the full error message. The answer will be in the linked question, you just have to put a bit of effort in to read it – Alan Birtles Apr 28 '20 at 20:04

0 Answers0