| I'm trying to compile this code with VC++ 7:
|
| class KeyboardInterface
|
| {
| public:
| ....
| std::vector<KBBits4KeyUp> KBKUBuffer(256, KBBuffer);
| ...
| }
|
| I get this error: error C2059: erreur de syntaxe : 'constant'
|
| I guess we can't use the constructor of a vector in a class
declaration,
| right??? How can I solve this problem? thanx in advance...
|
A class declaration requires a semicolon.
class KeyboardInterface
{
};
Lets consider a std::vector<int> and lets initialize a vector of 64
elements to 0 (hint: ctor initialization list)
---
// KeyboardInterface.h
#ifndef KEYBOARDINTERFACE_H_
#define KEYBOARDINTERFACE_H_
#include <vector>
class KeyboardInterface
{
std::vector<int> vn;
public:
KeyboardInterface();
~KeyboardInterface();
int getIndex(const int& n) const;
int getSize() const;
};
#endif // include guard KEYBOARDINTERFACE_H_
___
// KeyboardInterface.cpp
#include "KeyboardInterface.h"
const int NBUFFER(64); // could have been a member
KeyboardInterface::KeyboardInterface() : vn(NBUFFER, 0)
{
}
KeyboardInterface::~KeyboardInterface()
{
}
int KeyboardInterface::getIndex(const int& n) const
{
// error checking required: n must be less than NBUFFER
return vn[n];
}
int KeyboardInterface::getSize() const
{
return vn.size();
}
---
// test.cpp
#include "KeyboardInterface.h"
#include <iostream>
int main()
{
KeyboardInterface ki;
std::cout << "vn[0] = " << ki.getIndex(0) << std::endl;
std::cout << "vn[63] = " << ki.getIndex(63) << std::endl;
std::cout << "vector size = " << ki.getSize() << std::endl;
return 0;
}
---