Strange compile errors...
-
- KVRian
- Topic Starter
- 574 posts since 6 Jan, 2003 from Somewhere between ))o Left and Right o((
Hi,
I'm using VC++ 6.0,
I have a struct and I want to add to a std::list struct pointers.
#include <list>
using std::list;
typedef struct {
int time, note, velocity;
} Note_Event;
...
typedef std::list <Note_Event *> m_events;
....
Note_Event *event;
event = new Note_Event;
m_events.push_back(event);
I get this error :
c:\vstsdk\vstsdk2\source\vstxsynth2\event.cpp(51) : error C2065: 'm_events' : undeclared identifier
c:\vstsdk\vstsdk2\source\vstxsynth2\event.cpp(51) : error C2228: left of '.push_back' must have class/struct/union type
I tryed a lot of tips I read on the net, but it didn't fix it.
I'm using VC++ 6.0,
I have a struct and I want to add to a std::list struct pointers.
#include <list>
using std::list;
typedef struct {
int time, note, velocity;
} Note_Event;
...
typedef std::list <Note_Event *> m_events;
....
Note_Event *event;
event = new Note_Event;
m_events.push_back(event);
I get this error :
c:\vstsdk\vstsdk2\source\vstxsynth2\event.cpp(51) : error C2065: 'm_events' : undeclared identifier
c:\vstsdk\vstsdk2\source\vstxsynth2\event.cpp(51) : error C2228: left of '.push_back' must have class/struct/union type
I tryed a lot of tips I read on the net, but it didn't fix it.
-
- KVRAF
- 2458 posts since 3 Oct, 2002 from SF CA USA NA Earth
I think the line:
should lose the "typedef" - as written, you're creating a new type m_events rather than a list-of-events object.
Code: Select all
typedef std::list <Note_Event *> m_events;
-
- KVRian
- Topic Starter
- 574 posts since 6 Jan, 2003 from Somewhere between ))o Left and Right o((
No it's not that. I introduced the "typedef" trying to fix the bug. It looks like the micro$oft compiler is not aware that in the lineBorogove wrote:I think the line:
should lose the "typedef" - as written, you're creating a new type m_events rather than a list-of-events object.Code: Select all
typedef std::list <Note_Event *> m_events;
Code: Select all
std::list <Note_Event *> m_events;
Kind regards,
A.F.
-
Fire Sledge - Ohm Force Fire Sledge - Ohm Force https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=46
- KVRist
- 121 posts since 2 Nov, 2000 from 404 - Not found
With typedef you define a new type, not a new instance of list. You have to instanciate this new type afterwards to create a list object. So it should be :
-- Laurent
Code: Select all
typedef std::list <Note_Event *> EventList;
EventList m_events;
...
Note_Event* event = new Note_Event;
m_events.push_back(event);
-
- KVRAF
- 4641 posts since 20 Feb, 2004 from Gothenburg, Sweden
using std::list; ???
list is not a name-space...
in the h file
in cpp file
list is not a name-space...
in the h file
Code: Select all
include <list>
..
class Arne
{
void Method();
std::list<Note_Event *> m_events;
}
Code: Select all
void
Arne::Method()
{
Note_Event *event;
event = new Note_Event;
m_events.push_back(event);
}
Stefan H Singer
Musician, coder and co-founder of We made you look Web agency
Musician, coder and co-founder of We made you look Web agency
-
- KVRian
- Topic Starter
- 574 posts since 6 Jan, 2003 from Somewhere between ))o Left and Right o((
quote : using std::list; ???
yes.
in the h file
in cpp file
tryed that way too. The only difference in your code, is that I #include <list> in the cpp file.
Thanks, I will try this one too.
yes.
in the h file
Code: Select all
include <list>
..
class Arne
{
void Method();
std::list<Note_Event *> m_events;
}
Code: Select all
void
Arne::Method()
{
Note_Event *event;
event = new Note_Event;
m_events.push_back(event);
}
Thanks, I will try this one too.
-
- KVRian
- Topic Starter
- 574 posts since 6 Jan, 2003 from Somewhere between ))o Left and Right o((
edit : This is my class...
[/size][/code]
Code: Select all
#include <math.h>
#include <stdio.h>
//#include <dir.h>
#include <string.h>
#include <fstream.h>
#include <windows.h>
#include "Event.h"
#include "vstcontrols.h"
#include <list>
using std::list;
typedef struct {
int time, note, velocity;
} Note_Event;
EventQueue::EventQueue()
{
typedef std::list <Note_Event *> m_events;
};
EventQueue::~EventQueue()
{
};
void EventQueue::addNote(int time, int note, int velocity)
{
Note_Event *event;
event = new Note_Event;
event->time = time;
event->note = note;
event->velocity = velocity;
m_events.push_back(event);
};
int EventQueue::getEventCount()
{
return 0;
};
int EventQueue::getNextEventTime()
{
return 0;
};
int EventQueue::getNextEvent()
{
return 0;
};
bool EventQueue::isEmpty()
{
return false;
}
Code: Select all
#ifndef __events__
#define __events__
class EventQueue
{
public:
EventQueue();
~EventQueue();
protected :
virtual void addNote(int time, int note, int velocity);
virtual int getEventCount();
virtual int getNextEventTime();// return time of next event in queue without removing the event
virtual int getNextEvent();// return next event and remove from queue
virtual bool isEmpty(void);
private:
};
#endif
[/size][/code]
-
- KVRAF
- 4641 posts since 20 Feb, 2004 from Gothenburg, Sweden
You are declaring m_events as a local _TYPE_ (due to typedef, without typedef it would be a local variable which still is wrong ) in a method instead of declaring it as a member of the class. When declaring it in a method, no other methods could possibly know that this variable exists (and it does not exist outside of the method where you declared it).
declare it as a private member instead, like this
(and get rid of using std::list, list is not a namespace)
declare it as a private member instead, like this
(and get rid of using std::list, list is not a namespace)
Code: Select all
#ifndef __events__
#define __events__
class EventQueue
{
public:
EventQueue();
~EventQueue();
protected :
virtual void addNote(int time, int note, int velocity);
virtual int getEventCount();
virtual int getNextEventTime();// return time of next event in queue without removing the event
virtual int getNextEvent();// return next event and remove from queue
virtual bool isEmpty(void);
private:
std::list<Note_Event*> m_events;
};
#endif
Stefan H Singer
Musician, coder and co-founder of We made you look Web agency
Musician, coder and co-founder of We made you look Web agency
-
- KVRian
- Topic Starter
- 574 posts since 6 Jan, 2003 from Somewhere between ))o Left and Right o((
That's exactly where I started from. I declared it like that :
but I had those 2 errors anyway.
Damn, I don't have a decent compiler at work
Btw. Does it matter if I dont instantiate the EventQueue class at all ?
Thanks,
A.F.
Code: Select all
private:
std::list<Note_Event*> m_events;
Damn, I don't have a decent compiler at work
Btw. Does it matter if I dont instantiate the EventQueue class at all ?
Thanks,
A.F.
-
- KVRAF
- 4641 posts since 20 Feb, 2004 from Gothenburg, Sweden
You got to have the class declaration before the class definition (implementation).
What do you mean about the instantiation thingy? How could a method use members that does not exist?
What do you mean about the instantiation thingy? How could a method use members that does not exist?
Stefan H Singer
Musician, coder and co-founder of We made you look Web agency
Musician, coder and co-founder of We made you look Web agency
-
- KVRian
- Topic Starter
- 574 posts since 6 Jan, 2003 from Somewhere between ))o Left and Right o((
What I mean is, that the EventQueue class is not used in code at all, like :stefancrs wrote:You got to have the class declaration before the class definition (implementation).
What do you mean about the instantiation thingy? How could a method use members that does not exist?
my_queue = new EventQueue();
Normally I would call that from initProcess ();
And I was asking if that matters in this case.
-
- KVRAF
- 4641 posts since 20 Feb, 2004 from Gothenburg, Sweden
No, the class should compile without being used anywhere.
If you send me the whole class at hallen_stefan at yahoo.se I could take a look at it.
If you send me the whole class at hallen_stefan at yahoo.se I could take a look at it.
Stefan H Singer
Musician, coder and co-founder of We made you look Web agency
Musician, coder and co-founder of We made you look Web agency
-
- KVRAF
- 4641 posts since 20 Feb, 2004 from Gothenburg, Sweden
Fixed!
Only things I needed to change was to move the struct, the m_events declaration to the header file.
Only things I needed to change was to move the struct, the m_events declaration to the header file.
Stefan H Singer
Musician, coder and co-founder of We made you look Web agency
Musician, coder and co-founder of We made you look Web agency
-
- KVRian
- Topic Starter
- 574 posts since 6 Jan, 2003 from Somewhere between ))o Left and Right o((
It was the #include <list>stefancrs wrote:Fixed!
Only things I needed to change was to move the struct, the m_events declaration to the header file.
I had to include it in the header file too.
Anyway, I have more beginner problems.
One of my methods must return a pointer to a "clone" of the Note_Event struct. (clone, i mean clone = new Note_Event).
Since the Note_Event struct is defined inside the EventQueue class, i cant define as return parameter Note_Event*.
Code: Select all
protected :
virtual void addNote(int time, int note, int velocity);
virtual int getEventCount();
virtual int getNextEventTime//
virtual Note_Event* getNextEvent();//
Code: Select all
Note_Event* EventQueue::getNextNote() {
Note_Event *ev;
ev = m_events.pop_front();
return ev;
// more to be added
};
c:\vstsdk\vstsdk2\source\vstxsynth2\event.h(6) : see declaration of 'EventQueue'
c:\vstsdk\vstsdk2\source\vstxsynth2\event.cpp(47) : error C2065: 'm_events' : undeclared identifier
c:\vstsdk\vstsdk2\source\vstxsynth2\event.cpp(47) : error C2228: left of '.pop_front' must have class/struct/union type
So how can I do this ? I tryed to define the struct as public or static struct ... but than I get lot's of errors.
-
- KVRian
- 922 posts since 26 Mar, 2003 from Guildford, England
Its sometimes better to define the list as a pointer, so that you don't have to include the <list> header in the header file for you class. You have to forward declare the list class though:
This reduces dependencies, and in large projects can lead to drastically reduced compile times. It is fine to have partial classes (forward declared ones) as return-by-value types, or as pass-by-value types. In a real class, it is likely that you would want to declare a copy constructor and assignment operator to prevent wierd things happening.
Code: Select all
namespace std {
template<typename T> class allocator;
template<typename T, class A = allocator<T> > class list;
}
class SomeClass
{
public:
SomeClass();
private:
typedef std::list<int> IntList;
IntList *plist_;
};