这很奇怪。我收到包含<vector>
的错误:(编辑:适用于<list>
,但我不想放弃向量)
g++.exe -c -g -MMD -MP -MF build/Debug/Cygwin-Windows/main.o.d -o build/Debug/Cygwin-Windows/main.o main.cpp
from MemoryScanner.h:11,
from main.cpp:10:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_bvector.h: In member function `void std::vector<bool, _Alloc>::_M_insert_range(std::_Bit_iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag)':
In file included from /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/vector:72,
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_bvector.h:522: error: expected unqualified-id before '(' token
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_bvector.h: In member function `void std::vector<bool, _Alloc>::_M_fill_insert(std::_Bit_iterator, size_t, bool)':
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_bvector.h:823: error: expected unqualified-id before '(' token
from MemoryScanner.h:11,
from main.cpp:10:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc: In member function `void std::vector<_Tp, _Alloc>::_M_fill_insert(__gnu_cxx::__normal_iterator<typename _Alloc::pointer, std::vector<_Tp, _Alloc> >, size_t, const _Tp&)':
In file included from /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/vector:75,
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc:307: error: expected unqualified-id before '(' token
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc: In member function `void std::vector<_Tp, _Alloc>::_M_range_insert(__gnu_cxx::__normal_iterator<typename _Alloc::pointer, std::vector<_Tp, _Alloc> >, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag)':
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc:384: error: expected unqualified-id before '(' tokenmake[2]: Leaving directory `/cygdrive/k/Documents and Settings/Administrator/My Documents/NetBeansProjects/MemScan'
make[1]: Leaving directory `/cygdrive/k/Documents and Settings/Administrator/My Documents/NetBeansProjects/MemScan'
make[2]: *** [build/Debug/Cygwin-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
引用的行:
#include "MemoryScanner.h" // main.cpp:10
#include <vector> // MemoryScanner.h:12
编辑:
MemoryScanner.h
#ifndef MEMORYSCANNER_H
#define MEMORYSCANNER_H
#include <vector>
#include <windows.h>
using namespace std;
struct memblock {
int address;
int value;
};
class MemoryScanner {
private:
HANDLE _hProc;
vector<memblock> _addresses;
public:
MemoryScanner(HANDLE hProc);
MemoryScanner(const MemoryScanner& orig);
void scan(int value);
void display();
virtual ~MemoryScanner();
};
#endif /* MEMORYSCANNER_H */
的main.cpp
#include <iostream>
#include <windows.h>
#include "MemoryScanner.h"
using namespace std;
int main(int argc, char** argv) {
HWND hWnd = FindWindow(0, "Calculator");
if (hWnd == 0) {
cout << "Could not retrieve window handler" << endl;
} else {
DWORD pid;
GetWindowThreadProcessId(hWnd, &pid);
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
if (!hProc) {
cout << "Could not open process" << endl;
} else {
MemoryScanner* scanner = new MemoryScanner(hProc);
int value;
cout << "Enter value: ";
cin >> dec >> value;
scanner->scan(value);
scanner->display();
}
}
return 0;
}
答案 0 :(得分:0)
或许 MemoryScanner.h 定义了一个与 vector 标头使用的名称匹配的宏。您是否看过 vector 和 stl_bvector.h 中包含哪些代码行?
在我包含项目特定的标头之前,我尝试包含系统标头和外部库标头,以便在出现问题时,编译器更有可能指向我有权更改的文件。
答案 1 :(得分:0)
/捂脸。我只需要从#include <windows.h>
中移除main.cpp
,因为它已包含在MemoryScanner.h