The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Private class member access
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

thomas.lorenz

Germany
2 Posts

Posted - 03/02/2016 :  02:24:28 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 2016 b9.3.226
Operating System: Win 10 64

Hallo,

I am trying to write some software for data evaluation using Origin C and stumbled accross an error while creating a custom class. The following sniplett of code fails to compile with "Error, Can't access non_public member out of the class" in line 6 (return statement of compare):

class ClassTest{
public:
	ClassTest(int rank){this->m_rank = rank;}
	~ClassTest(){}
	int compare(const ClassTest &o){
		return o.m_rank - this->m_rank;
	}
private:
	int m_rank;
};


As far as I know accessing private members of the same class should be possible (at least it is in C++).
Is this a bug or do I get something wrong?

Thanks for your help,
Thomas

jasonzhao

China
262 Posts

Posted - 03/02/2016 :  04:09:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

You can work around the problem in this way:

class ClassTest{
public:
	ClassTest(int rank){
		this->m_rank = rank;
	}
	~ClassTest(){}
	int GetRank(){ return m_rank;}	
	int compare(const ClassTest &o){
		return o.GetRank()- this->m_rank;
	}	
private:
	int m_rank;
};




Best regards!
Jason
OriginLab Technical Service

Edited by - jasonzhao on 03/02/2016 04:10:31 AM
Go to Top of Page

thomas.lorenz

Germany
2 Posts

Posted - 03/02/2016 :  05:12:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hallo jasonzhao,

thanks for your reply and your suggestion.
I will solve my problem this way, but I was interested if this behavior is already known since it is nowhere documented.
(And in my opinion it is kind of weired to expose values of private members through public accessors. It feels like breaching encapsulation)

Best regards!
Thomas
Go to Top of Page

jasonzhao

China
262 Posts

Posted - 03/03/2016 :  01:39:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

I have recorded your query in our problem tracking base with ID ORG-12275. The developer will make further check.

Best regards!
Jason
OriginLab Technical Service
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000