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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Private class member access

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
thomas.lorenz Posted - 03/02/2016 : 02:24:28 AM
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
3   L A T E S T    R E P L I E S    (Newest First)
jasonzhao Posted - 03/03/2016 : 01:39:19 AM
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
thomas.lorenz Posted - 03/02/2016 : 05:12:33 AM
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
jasonzhao Posted - 03/02/2016 : 04:09:48 AM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000