I am creating two objects of the same class (using c++).
When I change the data of one object, the data of the other object is automatically changing. I know this is the way it works in c++.
However, is there a technique I can use in order to achieve what I want?
Lexer::token currentToken;
Lexer::token getNextToken()
{
return currentToken = lexer.GetToken();
}
//testing
Lexer lookAheadLexer = lexer;
Lexer::token lookAhead;
Lexer::token getLookAhead()
{
lookAheadLexer = lexer;
return lookAhead = lookAheadLexer.GetToken();
}
//testing
When the GetToken()
is called on the lookAheadLexer
, the class data is changing and it seems as if GetToken
is also called on the lexer
.
Followed this link Why do objects of the same class have access to each other's private data?
Thank you for your help