473,586 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vector inside a class

I'm trying to compile this code with VC++ 7:

class KeyboardInterfa ce

{

public:

.....

std::vector<KBB its4KeyUp> 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...

Lovens


Sep 25 '05 #1
2 4038
Lovens Weche wrote:
I'm trying to compile this code with VC++ 7:

class KeyboardInterfa ce

{

public:

....

std::vector<KBB its4KeyUp> 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...


class KeyboardInterfa ce
{
public:
//...
std::vector<KBB its4KeyUp> KBKUBuffer;
KeyboardInterfa ce();
}

KeyboardInterfa ce::KeyboardInt erface() : KBKUBuffer(256, KBBuffer)
{
}


Sep 25 '05 #2

"Lovens Weche" <fw****@videotr on.ca> wrote in message
news:G6******** ********@weber. videotron.net.. .
| I'm trying to compile this code with VC++ 7:
|
| class KeyboardInterfa ce
|
| {
| public:
| ....
| std::vector<KBB its4KeyUp> 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 KeyboardInterfa ce
{
};

Lets consider a std::vector<int > and lets initialize a vector of 64
elements to 0 (hint: ctor initialization list)
---
// KeyboardInterfa ce.h
#ifndef KEYBOARDINTERFA CE_H_
#define KEYBOARDINTERFA CE_H_

#include <vector>

class KeyboardInterfa ce
{
std::vector<int > vn;
public:
KeyboardInterfa ce();
~KeyboardInterf ace();
int getIndex(const int& n) const;
int getSize() const;
};

#endif // include guard KEYBOARDINTERFA CE_H_
___

// KeyboardInterfa ce.cpp
#include "KeyboardInterf ace.h"

const int NBUFFER(64); // could have been a member

KeyboardInterfa ce::KeyboardInt erface() : vn(NBUFFER, 0)
{
}

KeyboardInterfa ce::~KeyboardIn terface()
{
}

int KeyboardInterfa ce::getIndex(co nst int& n) const
{
// error checking required: n must be less than NBUFFER
return vn[n];
}

int KeyboardInterfa ce::getSize() const
{
return vn.size();
}
---
// test.cpp
#include "KeyboardInterf ace.h"
#include <iostream>

int main()
{
KeyboardInterfa ce 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;
}
---
Sep 25 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2082
by: ding feng | last post by:
I am a beginner. So this question could be very stupid. Would anyone help me to solve this problem? A formatted txt file is read. Then i need to look into a vector who is a member of a class to search the matched string and return this string. For example, this vector has (string1, string2, ...stringn). When the formatted txt file is read,...
9
2963
by: luigi | last post by:
Hi, I am trying to speed up the perfomance of stl vector by allocating/deallocating blocks of memory manually. one version of the code crashes when I try to free the memory. The other version seem to work. I would appreciate someone to comment on this. Version 1 (crashes on deallocating) #include <iostream>
1
2939
by: Venkat | last post by:
Hi All, I am getting unusual compile errors when i declare a vector as a private member of a class in .h file, but if i declare the same in .cpp file inside the definition of a function which is a member of the same class it is working fine. Here is my .h file #include <wtypes.h>
2
2225
by: sci | last post by:
class A; void function(vector<A>* l) { .... } main(){ vector<A> aAList; function(&aAList);
17
3341
by: Michael Hopkins | last post by:
Hi all I want to create a std::vector that goes from 1 to n instead of 0 to n-1. The only change this will have is in loops and when the vector returns positions of elements etc. I am calling this uovec at the moment (for Unit-Offset VECtor). I want the class to respond correctly to all usage of STL containers and algorithms so that it is...
11
6296
by: sw | last post by:
Hi, Is it possible to insert a class <vec> which has a vector<double> member, into the vector<vec> veclist for e.g? I've been getting compilation errors when trying to insert using the vector method push_back() -> c:\program files\microsoft visual studio\vc98\include\xutility(39) : error C2679: binary '=' : no operator defined which...
14
3984
by: Michael Sgier | last post by:
Hello If someone could explain the code below to me would be great. // return angle between two vectors const float inline Angle(const CVector& normal) const { return acosf(*this % normal); } // reflect this vector off surface with normal vector
24
2928
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public vector<Corres>{ public: void addCorres(Corres& c); //it do little more than push_back function. }
11
2125
by: arnuld | last post by:
this is the code which runs without any trouble: ----------------------------------------------------- #include <iostream> #include <string> #include <vector> struct Entry { std::string name; int e_num;
4
3421
by: kungfuelmosan | last post by:
Hey guys, Im just getting into c++ at the moment so please bare with me Basically i need to declare a vector<stringstringArray(50) inside a class, however by doing so i am getting the following error: error: expected identifier before numeric constant error: expected ';' or '...' before numeric constant But i can declare ...
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.