出于某种原因,即使我定义了 main() 函数,我仍然收到 LNK1561 错误。
我的 search.h 文件:
#pragma once
#include <iostream>
#include <fstream>
using namespace std;
namespace standard{
class Search
{
public:
bool sequential_find(int num);
bool recursive_binary_find(int num);
bool iterative_binary_find(int num);
void init_array();
void init_sorted_array();
void set_seed(int seed);
int getSize();
bool binSearch(int d, int low, int high);
// this is just for practice and debugging.
friend ostream& operator<< (ostream& out, const Search& s)
{
// put the code in here.
}
Search(int size,int seed=0);
~Search();
private:
int size;
int* array;
static int* data;
};
}
还有我的 search.cpp 文件:
#include "Search.h"
using namespace std;
namespace standard{
int main()
{
return 0;
}
// Search::Search(int size,int seed=0)
// {
//
// }
bool Search::sequential_find(int num)
{
for (int i=0; i<getSize(); i++)
{
if(data[i] == num)
{
return true;
}
}
return false;
}
bool Search::recursive_binary_find(int num)
{
int high = getSize()-1;
int low = 0;
return binSearch(num, low, high);
}
bool Search::binSearch(int d, int low, int high)
{
if (low > high)
return false;
int mid = (high+low)/2;
if (d == data[mid])
return true;
if (d < data[mid])
return binSearch(d, low, mid-1);
else
return binSearch(d, mid+1, high);
}
bool Search::iterative_binary_find(int num)
{
int high = getSize()-1;
int low = 0;
while (low <= high)
{
int mid = (high+low)/2;
if (num == data[mid])
return true;
else if (num < data[mid])
high = mid-1;
else if (num > data[mid])
low = mid+1;
}
return false;
}
void Search::init_array()
{
}
void Search::init_sorted_array()
{
}
void Search::set_seed(int seed)
{
}
int Search::getSize()
{
return size;
}
}
显然我在我的主要功能中没有做任何实质性的事情,我正在努力让它完全编译。