0

我正在做我的第一个 VC++ 项目并使用以下代码。该项目具有以下文件。

项目1.cpp

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

using namespace std;

int main (void)
{

    PopulateDB x;
    x.calcUpload();


    return 0;
}

填充数据库.h

#pragma once
#include "mysql_connection.h"
#include <cppconn/driver.h>

class PopulateDB
{
public:
    int calcUpload(void);
    PopulateDB(void);
    ~PopulateDB(void);

private:

    int updateMA(sql::Connection &);
};

填充数据库.cpp

#include "StdAfx.h"
#include "PopulateDB.h"
#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include "Technical.h"

using namespace std;

int updateMA(sql::Connection& con)
{
    sql::Statement *stmt;
    sql::ResultSet *res;
    int i;

    stmt = con.createStatement();
    res = stmt->executeQuery("SELECT * from PriceAMS");

    while(res->next())
    {
        cout << "Symbol " << i << " = " << res->getBlob("Symbol") << endl;
        i++;
    }

    delete stmt;
}

int calcUpload(void)
{
    cout << "Running Connection..." << endl;

    try 
    {
        sql::Driver *driver;
        sql::Connection *con;
        sql::Statement *stmt;
        sql::ResultSet *res;

/* Create a connection */
        driver = get_driver_instance();
        con = driver->connect("tcp://127.0.0.1:3306", "nishantd", "mySQLDB%passWord2013"); //we can initialize the user/pass in constructor
/* Connect to the MySQL test database */
        con->setSchema("testMMDB");
        cout << "Looks like it connected..." << endl;

        updateMA(*con);

        delete con;
    }

    catch (sql::SQLException &e)
    {
        cout << "# ERR: SQLException in " << __FILE__;
        cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
        cout << "# ERR: " << e.what();
        cout << " (MySQL error code: " << e.getErrorCode();
        cout << ", SQLState: " << e.getSQLState() << " )" << endl;
    }
    return 0;
}


PopulateDB::PopulateDB(void)
{
}


PopulateDB::~PopulateDB(void)
{
}

技术.h

#pragma once
#include <vector>

class Technical
{
public:

    float StandardMovingAverage(std::vector<float> values);
    float StdDev(std::vector<float> values);
    float Variance(std::vector<float> values);
    int RSI(std::vector<float> values);

    Technical(void);
    ~Technical(void);

};

技术.cpp

#include "StdAfx.h"
#include "Technical.h"
#include <cmath>
#include <vector>

using namespace std;

float Technical::StandardMovingAverage(vector <float> values)
{
    int sum=0;
    for(int i=0; i < values.size(); i++)
        sum+=values[i];
    return sum/values.size();
}

float Technical::StdDev(vector <float> values)
{
    float E=0;
    float ave = StandardMovingAverage(values); //this function just calculates the mean values
    for(int i=0; i < values.size(); i++)
        E+=(values[i]- ave)*(values[i]- ave);
    return sqrt(1/values.size()*E);
}

float Technical::Variance(vector <float> values)
{
    return StdDev(values)*StdDev(values);
}


Technical::Technical(void)
{
}


Technical::~Technical(void)
{
}

我在 VC++ 2010 中收到以下错误。我目前忽略了一些警告

1>Project1.obj : error LNK2001: unresolved external symbol "public: int __thiscall PopulateDB::calcUpload(void)" (?calcUpload@PopulateDB@@QAEHXZ)
1>D:\Project\CPP\Project1\Release\Project1.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我正在尝试解决这个问题并让我的代码正常工作。它更令人沮丧,因为我怀疑我错过了一些非常基本的东西,因为我是 VC++ 的新手,而且代码在目前的形式下并没有做太多的事情。

非常感谢所有帮助

谢谢,尼克

4

1 回答 1

1

您正在调用一个名为PopulateDB::calcUpload- class 的成员函数的函数PopulateDB。但是您从未真正实现过该功能。您确实实现了一个名为 的不同的、独立的、非成员函数::calcUpload,但您没有调用它。

在你的实现文件中,让它

int PopulateDB::calcUpload() {...}
于 2013-10-22T23:28:37.370 回答