making consistency of data member in the whole programme without using static keyword
In the below programme i use one boolean variable named check , which is being accessed inside main function by two objects of Tst1 and Test2 . But the value of check variable is not maintained in the programme . we can use static but i want to know some alternative way ..could anyone give me some hints on it ?
Thanks in advance .
Inside jointdeatils.h
#pragma once
class Jointdetails
{
public:
Jointdetails(void);
~Jointdetails(void);
bool check;
};
Inside jointdeatils.cpp
#include "Jointdetails.h"
Jointdetails::Jointdetails(void)
{
check = false ;
}
Jointdetails::~Jointdetails(void)
{
}
Inside analyzer.h
#pragma once
#include "Jointdetails.h"
class Analyzer
{
public:
Analyzer(void);
Jointdetails* GetJointDetails();
Jointdetails* m_ptheCTJointDetails;
~Analyzer(void);
};
Inside analyzer.cpp
#include "Analyzer.h"
#include "stddef.h"
Analyzer::Analyzer(void)
{
m_ptheCTJointDetails = new Jointdetails();
}
Analyzer::~Analyzer(void)
{
}
Jointdetails* Analyzer::GetJointDetails()
{
if(m_ptheCTJointDetails)
return m_ptheCTJointDetails;
else
return NULL;
}
Inside Test1.h
#pragma once
#include "Analyzer.h"
class Tst1
{
public:
Tst1(void);
Analyzer *analyzer1 ;
public:
~Tst1(void);
};
Inside Test1.cpp
#include "Tst1.h"
Tst1::Tst1(void)
{
analyzer1 = new Analyzer ;
}
Tst1::~Tst1(void)
{
}
Inside Test2.h
#pragma once
#include "Analyzer.h"
class Test2
{
public:
Test2(void);
Analyzer *analyzer2 ;
public:
~Test2(void);
};
Inside Test2.cpp
#include "Test2.h"
Test2::Test2(void)
{
analyzer2 = new Analyzer ;
}
Test2::~Test2(void)
{
}
Inside main.cpp
#include "Test2.h"
#include "Tst1.h"
#include "stdio.h"
int main()
{
Tst1 *test1 = new Tst1 ; //check = false
Test2 *test2 = new Test2 ; //check = false
test1->analyzer1->GetJointDetails()->check = true ;
if(test2->analyzer2->GetJointDetails()->check )
printf("Check value is changed");
else
printf("Check value is not changed");
return 0 ;
}
View Answers
Related Tutorials/Questions & Answers:
Advertisements
static keyword in java
.style1 {
color: #0000FF;
}
static keyword in java
We are going to discuss about
static keyword in java. The
static keyword
is a special
keyword in java programming language. A
static member belongs to a
class
static keywordstatic keyword please give some detail about
Static keyword.
Static Variables
Static variables are class variables that are shared... method can access only
static data. It can not access non-
static data (instance
static keywordstatic keyword Hii,
In which portion of memory
static variables stored in java.
Is it take memory at compile time?
thanks
deepak mishra
Static keyword in public static void main:
static keyword indicates that this method can be invoked simply by
using the name... is declared by
using static keyword. Following is an example of
static declaration...
Static keyword in public
static void main Hi,
I have seen
data and analytics graduate programme:
data and analytics graduate
programme
Try to provide me good examples or tutorials links so that I can learn the
topic "
data and analytics graduate...
data and analytics graduate programme Hi,
I am beginner in
Data static keyword in interfacestatic keyword in interface Could any one explain,why
static keyword implict (or explict ) come in interface?
I asked lot of persons about this question, but nobody did not answered clearly. please explain clearly and say what
PHP Static Variable and Methods should use
static methods and variables.
Static keyword is used to make only one... of that attribute.
Static data are used when some
data has to share within... then we can access the method
using class,
without instantiating any object
static Java Keyword
static Java
Keyword
The
static is a
keyword defined in the java programming
language. Keywords... in java programming language likewise the
static
keyword indicates the following
Access Static Member Of The Class Through Object
Access
Static Member Of The Class Through Object
... that work
without any object of the class.
Static methods are limited to calling other
static
methods in the class and to
using only
static variables
programmeprogramme
Using an ATM, customer can access their bank accounts...
programme to implement a simple ATM for 15 customers. Initially you have to store...
using array(s). Then the program ask user to input account number and password
without using built-in functionswithout using built-in functions Hai sir...
Please help me to solve this...
Findout occurances of each string in every another string
(built - in functions are not at all allowed)
all, and, sand, falling wall and sand
How to access sub class member using super class objectHow to access sub class
member using super class object class A{
}
class B extends A{
int b=1;
}
class Test{
public
static void main(String args[])
{
what to do here to access sub class variable b
using super class object
Sorting arraylist without using Collection.sort()Sorting arraylist
without using Collection.sort() Hi,
How can I sort an arraylist
without using Collection.sort() nad also I am not allowed to use any other
data structure in the program? Is there any algorithm by
using which I
using tiles without strutsusing tiles
without struts Hi
I am trying to make an application
using tiles 2.0.
Description of my web.xml is as follows:
tiles
org.apache.tiles.web.startup.TilesServlet
static is applied to
member variables, it means that the
static variable is shared among all instances of the class.
When
static is applied to methods, the
static keyword...static what r the main uses of
static in java
Hi Friend
java programme java
programme 1.....
programme for reading 10 values for 10 variables
using scanner class
2....declares all types of primitive
data inside main method
Making 301 redirection by using <c:redirect>Making 301 redirection by
using How can i set the status as 301 when
using tag?
When i use , I am able to redirect to the desired URL (here, Google page) but I get 302 as the status of redirect. I need this status as 301.
Any
String length without using length() method in javaString length
without using length() method in java How to count length of string
without using length() method in java?
Here is Example... the number of character into the given string
without using the length() method
Round of to a multiple of 5 without using functionRound of to a multiple of 5
without using function Please help me out...
U enter values like 239, 2543.876, 962....
Give me an equation
without using any function which will give output of 240, 2545, 960 respectively
Round of to a multiple of 5 without using functionRound of to a multiple of 5
without using function Please help me out...
U enter values like 239, 2543.876, 962....
Give me an equation
without using any function which will give output of 240, 2545, 960 respectively
Java repeat string without using loopsJava repeat string
without using loops
In this section, you will learn how to repeat string
without using for loops.
The given example accepts the number of times and iterates the string to the
number of times set by the user
without Static variable in java.
Static variable is accessed
without creating object of class
using class
name...
Static variable in java.
Static is a
keyword in java used to create
static...; Classname.variablename;
Example:
Using Static Variable.
public class Staticvariable
Member Classes.
Member classes can also use instances of the same class
without explicit
delegation. Only the
member classes can be declared as
static.
Local...
Member Classes
Can you become a data scientist without a degree?Can you become a
data scientist
without a degree? Hi,
I am beginner... to learn:
Can you become a
data scientist
without a degree?
Try to provide me... become a
data scientist
without a degree?". Also tell me which is the good
send without authentication mail using java - JavaMailsend
without authentication mail
using java Dear All,
I am tring to send simple mail
without authentication
using java.
is it possible, could i send email
without authentication.
I have written following code.
public
Static Variable of a class, an object, is created.
When
static is applied to
member variables....
When
static is applied to methods, the
static keyword means that the specified...
Static Variable What is the basic use of introducing
static variable
Swap two numbers without using third variableSwap two numbers
without using third variable
In this section we are going to swap two variables
without using the third variable. For this, we have used... from the command prompt. Instead of
using temporary variable, we have done some