0

我想为我的程序创建一些模块。我想调用一个函数并将一个向量作为参数传递。返回值也应该是一个向量。

我的代码看起来像这样

main.cpp
//BlueSmart.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
#include "stdafx.h"

#define WIN32_LEAN_AND_MEAN

using namespace std;

#pragma comment(lib, "Irprops.lib")



BLUETOOTH_FIND_RADIO_PARAMS m_bt_find_radio = {
sizeof(BLUETOOTH_FIND_RADIO_PARAMS)
};

BLUETOOTH_RADIO_INFO m_bt_info = {
sizeof(BLUETOOTH_RADIO_INFO),
0,
};

BLUETOOTH_DEVICE_SEARCH_PARAMS m_search_params = {
sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS),
1,
0,
1,
1,
1,
15,
NULL
};

BLUETOOTH_DEVICE_INFO m_device_info = {
sizeof(BLUETOOTH_DEVICE_INFO),
0,
};

HANDLE m_radio = NULL;
HBLUETOOTH_RADIO_FIND m_bt = NULL;
HBLUETOOTH_DEVICE_FIND m_bt_dev = NULL;

int wmain(int argc, wchar_t **args) {

while(true) {
m_bt = BluetoothFindFirstRadio(&m_bt_find_radio, &m_radio);

do {
  localBluetoothDevices ();

  m_search_params.hRadio = m_radio;
  ::ZeroMemory(&m_device_info, sizeof(BLUETOOTH_DEVICE_INFO));
  m_device_info.dwSize = sizeof(BLUETOOTH_DEVICE_INFO);
  m_bt_dev = BluetoothFindFirstDevice(&m_search_params, &m_device_info);

  vector<wstring> vec;
  int m_device_id = 0;
  do {
   wostringstream tmp;
   ++m_device_id;
   //Something like this <----------------------------------------
   externBluetoothDevices (vec);
   //Something like this <----------------------------------------

      wprintf(L"********************************************************************** \n");
   wprintf(L"\tDevice %d:\r\n", m_device_id);
   wprintf(L"\t\tName: %s\r\n", m_device_info.szName);
   wprintf(L"\t\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n", m_device_info.Address.rgBytes[0], m_device_info.Address.rgBytes[1], m_device_info.Address.rgBytes[2], m_device_info.Address.rgBytes[3], m_device_info.Address.rgBytes[4], m_device_info.Address.rgBytes[5]);
   wprintf(L"====================================================================== \n");


   for (int i = 0; i < 6; i++) {
    tmp << hex << m_device_info.Address.rgBytes [i];
    if (i < 5)
     tmp << L':';
   }

   vec.push_back(tmp.str());

  } while(BluetoothFindNextDevice(m_bt_dev, &m_device_info));


  BluetoothFindDeviceClose(m_bt_dev);
  //Sleep(10*1000*60);
  Sleep(10000);

} while(BluetoothFindNextRadio(&m_bt_find_radio, &m_radio));
BluetoothFindRadioClose(m_bt);
}
return 0;
}

//Lokal verfügbare bzw. angeschlossene Bluetooth-Devices
void localBluetoothDevices (){
  int m_radio_id = 0;
  m_radio_id++;
  BluetoothGetRadioInfo(m_radio, &m_bt_info);      
  //Lokaler Bluetoothadapter
  wprintf(L"====================================================================== \n");
  wprintf(L"Local Device Nr. %d\n", m_radio_id);
  wprintf(L"\tName: %s\r\n", m_bt_info.szName);
  wprintf(L"\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n",      m_bt_info.address.rgBytes[0], m_bt_info.address.rgBytes[1], m_bt_info.address.rgBytes[2], m_bt_info.address.rgBytes[3], m_bt_info.address.rgBytes[4], m_bt_info.address.rgBytes[5]);

 }

//Extern verfügbare bzw. Bluetooth-Devices
 vector<wstring> externBluetoothDevices (vector<wstring> &vec){
return vec;
 }

标准数据文件

 #pragma once

 #include "targetver.h"

 #include <stdio.h>
 #include <tchar.h>
 #include <winsock2.h>
 #include <windows.h>
 #include <stdlib.h>
 #include <bthdef.h>
 #include <BluetoothAPIs.h>
 #include <iostream>
 #include <vector>
 #include <algorithm>
 #include <string>
 #include <sstream>
 #include <iomanip>
 #include <conio.h>

 void localBluetoothDevices ();
 vector<wstring> externBluetoothDevices (vector<wstring>);

它说向量不是已知类型。我究竟做错了什么?

4

2 回答 2

1

在 stdafx.h 中替换

vector<wstring> externBluetoothDevices (vector<wstring>);

std::vector<std::wstring> externBluetoothDevices (std::vector<std::wstring>);

基本上问题在于,尽管您using namespace std;在看到 using 声明之前放入了不计入头文件的 cpp 文件。

另请注意,您在 cpp 文件中的定义是不同的。在 cpp 文件中,您有一个参考

vector<wstring> externBluetoothDevices (vector<wstring>&);

决定你真正想要的。

于 2012-10-26T22:25:46.747 回答
0

你应该传递一个向量的指针。

于 2012-10-27T00:50:11.990 回答