Hi,
I added the following line to my code within a class declaration:
std::vector<Dat e> m_duedates(100) ;
I also tried:
std::vector<Dat e> m_duedates(100, Date());
My program compiles and runs fine without this line, but with it (the first
style above) I get the error:
error C2059: syntax error : 'constant'
Date is a class with a default constructor Date()
The help didn't help explain the cause of this error. Any ideas??
I was just going to use an array of type Date but the compile kept throwing up
on that too.
Thanks!
Math 16 2168
Honestmath wrote: My program compiles and runs fine without this line, but with it (the first style above) I get the error:
error C2059: syntax error : 'constant'
I have no idea what error C2059 means. My compiler doesn't generate this
error. Date is a class with a default constructor Date()
The help didn't help explain the cause of this error. Any ideas??
I was just going to use an array of type Date but the compile kept throwing up on that too.
I can't help you without seeing your *Date* class.
KPB
> std::vector<Dat e> m_duedates(100) ;
I also tried:
std::vector<Dat e> m_duedates(100, Date());
My program compiles and runs fine without this line, but with it (the first style above) I get the error:
try this :
class tet
{
std::vector<Dat e> m_duedates;
public:
tet() : m_duedates(100) {}
};
Honestmath wrote: I added the following line to my code within a class declaration:
std::vector<Dat e> m_duedates(100) ;
You cannot initialise members inside a class _definition_ (I am sure
you meant definition and not declaration).
Non-static data members need to be initialised in the constructor
initialiser list. Read about it in your favourite C++ book. I also tried:
std::vector<Dat e> m_duedates(100, Date());
My program compiles and runs fine without this line, but with it (the first style above) I get the error:
error C2059: syntax error : 'constant'
Date is a class with a default constructor Date()
The help didn't help explain the cause of this error. Any ideas??
I was just going to use an array of type Date but the compile kept throwing up on that too.
V
cyrusNew wrote: std::vector<D ate> m_duedates(100) ;
I also tried:
std::vector<D ate> m_duedates(100, Date());
My program compiles and runs fine without this line, but with it (the first style above) I get the error:
try this :
class tet { std::vector<Dat e> m_duedates; public: tet() : m_duedates(100) {} };
Yep... sorry to the original OP about my last post. Yeah, since you
declared this vector as a class member, your declarations won't work as
written.
KPB
KPB wrote: Honestmath wrote:
My program compiles and runs fine without this line, but with it (the first style above) I get the error:
error C2059: syntax error : 'constant'
I have no idea what error C2059 means. My compiler doesn't generate this error.
Date is a class with a default constructor Date()
The help didn't help explain the cause of this error. Any ideas??
I was just going to use an array of type Date but the compile kept throwing up on that too.
I can't help you without seeing your *Date* class.
Too bad. There is no need to actually see the Date class because the OP
was trying to initialise a 'vector'.
Similar to this:
#include <vector>
class A {
std::vector<int > blah(100); // will produce the same error
};
it needs to be
#include <vector>
class A {
std::vector<int > blah; // declaration only!
public:
A() : blah(100) {}
};
V
Victor Bazarov wrote: KPB wrote:
Honestmath wrote:
My program compiles and runs fine without this line, but with it (the first style above) I get the error:
error C2059: syntax error : 'constant' I have no idea what error C2059 means. My compiler doesn't generate this error.
Date is a class with a default constructor Date()
The help didn't help explain the cause of this error. Any ideas??
I was just going to use an array of type Date but the compile kept throwing up on that too.
I can't help you without seeing your *Date* class.
Too bad. There is no need to actually see the Date class because the OP was trying to initialise a 'vector'.
Similar to this:
#include <vector> class A { std::vector<int > blah(100); // will produce the same error };
it needs to be
#include <vector> class A { std::vector<int > blah; // declaration only! public: A() : blah(100) {} };
V
ok
Victor Bazarov wrote: Too bad. There is no need to actually see the Date class because the OP was trying to initialise a 'vector'.
Yes but after looking at his question further, he didn't acutally say
that it was a class member that he was trying to initialize, did he?
It could've been a line written in a member function defn. within a
class def, right? Highly unlikely but possible. If this were the case,
his vector declarations should've worked.
The point is, he didn't say it was a class member so at first, I didn't
register it as a class member. Kudos to you for reading between the lines.
Do you see my point now or can I expect more of these snide little
remarks from you?
Thanks,
KPB
Uzytkownik "KPB" <k@w.net> napisal w wiadomosci
news:yH******** ***********@fe1 0.lga... Victor Bazarov wrote:
Too bad. There is no need to actually see the Date class because the OP was trying to initialise a 'vector'.
Yes but after looking at his question further, he didn't acutally say that it was a class member that he was trying to initialize, did he?
It could've been a line written in a member function defn. within a class def, right? Highly unlikely but possible. If this were the case, his vector declarations should've worked.
The point is, he didn't say it was a class member so at first, I didn't register it as a class member. Kudos to you for reading between the lines.
Do you see my point now or can I expect more of these snide little remarks from you?
Thanks, KPB
exactly, I actually wrote a quick example code in MSVC and it printed error
C2059 :)
KPB wrote: Victor Bazarov wrote:
Too bad. There is no need to actually see the Date class because the OP was trying to initialise a 'vector'.
Yes but after looking at his question further, he didn't acutally say that it was a class member that he was trying to initialize, did he?
Well, reading the very first sentence in the original post, I see
<< I added the following line to my code within a class declaration:
std::vector<Dat e> m_duedates(100) ; >>
what else could it be but a class member? "within a class declaration"
should have given you enough of a clue. It could've been a line written in a member function defn. within a class def, right? Highly unlikely but possible. If this were the case, his vector declarations should've worked.
Yes, it should have. But it didn't. Couldn't that be a clue in itself?
You know how to initialise a vector, apparently. And how screwed up
should the 'Date' class be to make a compiler barf at both
std::vector<Dat e> m_duedates(100) ;
_and_
std::vector<Dat e> m_duedates(100, Date());
by complaining about the constant '100'?
The point is, he didn't say it was a class member so at first, I didn't register it as a class member. Kudos to you for reading between the lines.
Thanks.
Do you see my point now or can I expect more of these snide little remarks from you?
Well you're trying to read between even finer lines than I could ever.
If you consider my remarks as snide and little, I'll stop. Sorry I
bothered you.
V This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: bartek d |
last post by:
Hello,
Regarding my previous question about a class which is used to store a
variable type vector. I tried to be more elaborate on the code.
I'd be grateful for your suggestions. Am I going in the wrong direction
with the implementation? I'm asking this because I don't have much
experience with C++. Thanks in advance.
The main problem I see with this class, is that the code which uses it
|
by: Jason Heyes |
last post by:
To my understanding, std::vector does not use reference counting to avoid
the overhead of copying and initialisation. Where can I get a reference
counted implementation of std::vector? Thanks.
|
by: Janina Kramer |
last post by:
hi ng,
i'm working on a multiplayer game for a variable number of players and on the client side, i'm using a std::vector<CPlayer> to store
informatik about the players. CPlayer is a class that contains another std::vector<CPosition>. Because one of the players is the
client itself (and the size of the vector<CPlayer> doesn't change during a game), i thought i could store a
std::vector<CPlayer>::iterator "localplayer" that points to the...
|
by: canned.net |
last post by:
I have a class Scene that has several subclasses: World, Vault, etc.
I fill a vector with these classes and then cannot go through and
delete them. What's the trick to deleting pointers from a vector?
Code:
std::vector<Scene*> scenes;
void initializeGame()
|
by: Anonymous |
last post by:
Is there a non-brute force method of doing this?
transform() looked likely but had no predefined function object.
std::vector<double> src;
std::vector<int> dest;
std::vector<double>::size_type size = src.size();
dest.reserve(size);
for (std::vector<int>::size_type i = 0;
| |
by: zl2k |
last post by:
hi, c++ user
Suppose I constructed a large array and put it in the std::vector in a
function and now I want to return it back to where the function is called.
I can do like this:
std::vector<int> fun(){
//build the vector v;
return v;
}
|
by: Bobrick |
last post by:
Hi.
Thanks to everyone who replied to my last post, it turns out it wasn't
the line where I was trying to treat the variable in question as an
array which was the problem, but the line above.
char temp;
std::vector<unsigned charmmessage;
while (!done){
|
by: jubelbrus |
last post by:
Hi
I'm trying to do the following.
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>
class {
|
by: Daniel Pitts |
last post by:
I have std::vector<Base *bases;
I'd like to do something like:
std::for_each(bases.begin(), bases.end(), operator delete);
Is it possible without writing an adapter? Is there a better way? Is
there an existing adapter?
Thanks,
Daniel.
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |