Connecting Tech Pros Worldwide Forums | Help | Site Map

Pointer problem

Member
 
Join Date: Nov 2006
Location: Houston, Texas
Posts: 46
#1: Jan 4 '07
Trying to load a vector, I got the following messages:

Member
 
Join Date: Nov 2006
Location: Houston, Texas
Posts: 46
#2: Jan 4 '07

re: Pointer problem


d:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_algobase.h:247: error: no match for 'operator*' in '*__result'
Member
 
Join Date: Nov 2006
Location: Houston, Texas
Posts: 46
#3: Jan 4 '07

re: Pointer problem


d:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_algobase.h:249: error: no match for 'operator++' in '++__result'
Member
 
Join Date: Nov 2006
Location: Houston, Texas
Posts: 46
#4: Jan 4 '07

re: Pointer problem


Here is the WindDataReceiveBuffer header:
Member
 
Join Date: Nov 2006
Location: Houston, Texas
Posts: 46
#5: Jan 4 '07

re: Pointer problem


Expand|Select|Wrap|Line Numbers
  1. #ifndef WINDDATARECEIVEBUFFER_H_
  2. #define WINDDATARECEIVEBUFFER_H_
  3.  
  4. #include "windsTableElement.h"
  5. #include <vector>
  6. typedef std::vector< WindsTableElement > WindTable;
  7. WindTable wt_;
  8.  
  9. class WindDataReceiveBuffer
  10. {
  11.  
  12.     static WindDataReceiveBuffer* instance_;
  13.  
  14. protected:
  15.     WindDataReceiveBuffer();
  16.     ~WindDataReceiveBuffer();
  17.     WindDataReceiveBuffer(const WindDataReceiveBuffer&);
  18.     WindDataReceiveBuffer& operator=(const WindDataReceiveBuffer&);
  19.  
  20. public:
  21.     static WindDataReceiveBuffer* Instance();
  22.     void setData(char*, unsigned int);
  23.     WindTable getWindTable();      
  24.  
  25. };
  26.  
  27. #endif /*WINDDATARECEIVEBUFFER_H_*/
  28.  
Member
 
Join Date: Nov 2006
Location: Houston, Texas
Posts: 46
#6: Jan 4 '07

re: Pointer problem


And the implementation code:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include "WindDataReceiveBuffer.h"
  3.  
  4. WindDataReceiveBuffer* WindDataReceiveBuffer::instance_ = 0;
  5.  
  6. WindDataReceiveBuffer* WindDataReceiveBuffer::Instance()
  7. {
  8.     if (instance_ == 0)
  9.     {
  10.         instance_ = new WindDataReceiveBuffer;
  11.     }
  12.     return instance_;
  13. }
  14.  
Member
 
Join Date: Nov 2006
Location: Houston, Texas
Posts: 46
#7: Jan 4 '07

re: Pointer problem


Expand|Select|Wrap|Line Numbers
  1. WindDataReceiveBuffer::WindDataReceiveBuffer()
  2. {
  3.  
  4. }
  5.  
  6. WindDataReceiveBuffer::~WindDataReceiveBuffer()
  7. }
  8.  
  9. void WindDataReceiveBuffer::setData(char* inBufr, 
  10.     unsigned int size)
  11. {      
  12.     std::copy(inBufr, inBufr+(size * sizeof(WindsTableElement)), wt_);
  13. }
  14.  
  15. WindTable WindDataReceiveBuffer::getWindTable()
  16. {
  17.     return wt_;
  18. }
  19.  
Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#8: Jan 4 '07

re: Pointer problem


Quote:

Originally Posted by PaperPilot

And the implementation code:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include "WindDataReceiveBuffer.h"
  3.  
  4. WindDataReceiveBuffer* WindDataReceiveBuffer::instance_ = 0;
  5.  
  6. WindDataReceiveBuffer* WindDataReceiveBuffer::Instance()
  7. {
  8.     if (instance_ == 0)
  9.     {
  10.         instance_ = new WindDataReceiveBuffer;
  11.     }
  12.     return instance_;
  13. }
  14.  

When you define instance_ for the first time (your first line of code here), don't include the WindDataReceiveBuffer* before the WindDataRetrieveBuffer::instance_ declaration. Including this makes it seem like a function which would be returning a variable of type WindDataReceiveBuffer*, which works for your Instance() function, but not a static variable declaration.
Member
 
Join Date: Nov 2006
Location: Houston, Texas
Posts: 46
#9: Jan 4 '07

re: Pointer problem


It seems I need to overload the operators ++ and * for the pointer __result.

Can you help?
(Sorry for using so many posts, but it is the only way I could get all the code in.
Refer to the "Incrementing a pointer" thread for the windsTableElement class code.)
Member
 
Join Date: Dec 2006
Posts: 38
#10: Jan 4 '07

re: Pointer problem


the third argument to std::copy must be an output iterator, not an object. So, you can use a pointer, or an actual iterator class, etc. Refer to the std::copy documentation for more info.
Member
 
Join Date: Nov 2006
Location: Houston, Texas
Posts: 46
#11: Jan 4 '07

re: Pointer problem


Quote:

Originally Posted by Ganon11

When you define instance_ for the first time (your first line of code here), don't include the WindDataReceiveBuffer* before the WindDataRetrieveBuffer::instance_ declaration. Including this makes it seem like a function which would be returning a variable of type WindDataReceiveBuffer*, which works for your Instance() function, but not a static variable declaration.

The static member variable instance_ contains a pointer to an instantiation of WindDataReceiveBuffer, making sure using routines can only construct one of them.
Reply