I have created a small c++ application with a header file, a cpp file, and a main function. I expected that the header file would be an interface
, that would just define my functions and properties, but the cpp file would be the one to implement.
However when I create my files, in my main
function I have a breakpoint and try to step into my method, it just takes me straight to the header file definition instead of the implementing cpp file. Here is my code:
//header file
#pragma once
#include <string>
#include <SQLAPI.h>
class DbConnection
{
public:
int Id, Age;
std::string Name;
void ConnectToDatabase(const std::string databaseName) { }
void Retrieve(const std::string table) { }
};
Here is my cpp file:
#include "DbConnection.h"
#include <string>
#include <SQLAPI.h>
#include <iostream>
SAConnection sqlCon;
SACommand sqlCmd(&sqlCon);
int Id, Age;
std::string Name;
void ConnectToDatabase(const std::string databaseName)
{
sqlCon.Connect(
databaseName,
",
",
SA_SQLServer_Client);
}
void Retrieve(const std::string table)
{
//code to retrieve data
std::cout << "success";
}
My main function which is in a separate cpp file. I set a breakpoint and attempt to step into the method Retrieve
and it takes me to the header file instead of the cpp. Any help with debugging is appreciated.
#include "DbConnection.h"
#include <stdio.h>
#include <iostream>
int main()
{
DbConnection con;
con.ConnectToDatabase(
"databaseParameter");
con.Retrieve("tableParameter");
return 0;
}
I assume it is one of two things, either my debugger in visual studio 2019 is not set to the proper setting, or it has to do with how my #include "DbConnection.h"
statements are included in both cpp files.
Two things:
You have to write in the cpp file
void DbConnection::ConnectToDatabase(const std::string databaseName) {... }
and so for the Retrieve function to tell the compiler that this is the function of the class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.