Thread: error with function

  1. #1
    Registered User
    Join Date
    Jul 2006
    Location
    Kingston, Ontario
    Posts
    12

    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!

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Seattle
    Posts
    30
    This probably isn't causeing that error but I can see two places where you're returning a bool instead of an int.

  4. #4
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Send the class definition code if possible.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  5. #5
    Registered User
    Join Date
    Jul 2006
    Location
    Kingston, Ontario
    Posts
    12
    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?

  6. #6
    Registered User
    Join Date
    Jan 2006
    Location
    Seattle
    Posts
    30
    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
    }
    Last edited by Peter5897; 07-26-2006 at 01:05 PM.

  7. #7
    Registered User
    Join Date
    Jul 2006
    Location
    Kingston, Ontario
    Posts
    12
    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;
    };

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> 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.

  9. #9
    Registered User
    Join Date
    Jul 2006
    Location
    Kingston, Ontario
    Posts
    12
    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);
    }

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    There you go!
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  11. #11
    Registered User
    Join Date
    Jul 2006
    Location
    Kingston, Ontario
    Posts
    12
    ok maybe this is stupid but i'm still not really sure how to fix this

  12. #12
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    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
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  13. #13
    Registered User
    Join Date
    Jul 2006
    Location
    Kingston, Ontario
    Posts
    12
    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 &center, GLfloat radius) const;
    };
    the errors say "error C2259: 'BMLDrawable' : cannot instantiate abstract class"

    any clue what that means?

  14. #14
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    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?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  15. #15
    Registered User
    Join Date
    Jul 2006
    Location
    Kingston, Ontario
    Posts
    12
    i'm not really sure what a pure virtual function is...how would i know?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM