-
error with function
Hi,
I am trying to write a function but keep getting an error when I try to build. I'm not very experienced with c++ so I can't really figure out what the error means. The funcion is called like this:
Code:
nMarkerCount = netClient.GetMarkerCount();
and it looks like this:
Code:
int BMLClient::GetMarkerCount(void)
{
if (!m_bConnected) return 0; //??
long cmd = 3;
if (!Send(&cmd, sizeof(cmd)))
{
std::cout << "Unable to send <get marker data> command" << std::endl;
return false;
}
long count;
if (!Recv(&count,sizeof(count)))
{
std::cout << "Unable to get marker count" << std::endl;
return false;
}
m_nMarkerCount = count;
m_buffer = new double[count*3];
m_bConnected = true;
return m_nMarkerCount;
}
I have declared it as public in the header file like this:
Code:
int GetMarkerCount(void);
The error that I get says: error C2662: 'BMLClient::GetMarkerCount' : cannot convert 'this' pointer from 'const BMLClient' to 'BMLClient &'
Can anyone tell from what I've posted what this error means? Thanks!
-
If the line in the header file is within a class, you're probably calling the function on a const object. How is netClient declared?
-
This probably isn't causeing that error but I can see two places where you're returning a bool instead of an int.
-
Send the class definition code if possible.
-
netClient is declared as:
Code:
protected:
BMLClient netClient;
in this class:
Code:
class BMLDrawable: public osg::Drawable
i'm not sure what you mean by the class definition code....what else do i need to post?
-
Post your .h where your class is defined.
If your GetMarkerCount(void) function is defined within the BMLDrawable class you need to say...
Code:
int BMLDrawable::GetMarkerCount(void)
{
// stuff
}
-
ok hopefully this is the one
Code:
#pragma once
#include <winsock2.h>
#include "Vector3.h"
class BMLClient
{
public:
BMLClient(void);
virtual ~BMLClient(void);
bool Connect(void);
void Disconnect(void);
bool isConnected(void) const { return m_bConnected; }
int GetMarkerCount(void);
void GetFrame(CVector3* buf) const;
protected:
bool m_bConnected; // true when connection to server established successfully
int m_nMarkerCount; // number of targets being tracked
SOCKET m_socket; // network socket connection to BML server
double *m_buffer; // buffer for frame data
bool Send(void* buf, long size) const;
bool Recv(void* buf, long size) const;
};
-
>> nMarkerCount = netClient.GetMarkerCount();
The place that the function call above is made is probably inside a BMLDrawable member function, right? If so, then is that member function const? Show the declaration of the function that contains the line above.
-
yup it's a const....here it is:
Code:
void BMLDrawable::drawImplementation (osg::State& state) const
{
if (!netClient.isConnected()) return;
nMarkerCount = netClient.GetMarkerCount();
// draw a sphere at each joint
glColor3fv(red);
glEnable(GL_LIGHTING);
for (int m=0; m<nMarkerCount; m++)
GenSphere(frameData[m],BALL_RADIUS);
// get next batch of frame data
netClient.GetFrame(frameData);
}
-
-
ok maybe this is stupid but i'm still not really sure how to fix this
-
Well.. what is happening, and Daved so cleverly guessed at, is that you are calling GetMarkerCount() which alters data members of your class from within a const member function named drawImplementation(). So...
drawImplementation() is really not a const function is it? :)
remove the const from both the declaration and definition and it should be ok
-
hmmm yea that's the first thing i tried but it's giving me more errors in this class:
Code:
class BMLDrawable: public osg::Drawable {
public:
BMLDrawable();
virtual ~BMLDrawable();
virtual osg::Object* cloneType() const
{
return new BMLDrawable();
}
virtual osg::Object* clone(const osg::CopyOp&) const
{
return new BMLDrawable();
}
bool computeBound() const;
virtual void drawImplementation(osg::State& state);
protected:
BMLClient netClient;
CVector3 *frameData;
int nMarkerCount;
GLuint nSphere;
void GenSphere (CVector3 ¢er, GLfloat radius) const;
};
the errors say "error C2259: 'BMLDrawable' : cannot instantiate abstract class"
any clue what that means?
-
I think that instead you just solved a problem and it is now detecting another.
Does osg::Object have any pure virtual functions? And if so... are all of them being defined in BMLDrawable?
-
i'm not really sure what a pure virtual function is...how would i know?