Circular dependency

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
3 posts • Page 1 of 1
uxout
Posts:82
Joined: Wed Jul 20, 2016 12:07 pm

Circular dependency

Post by uxout »

Hello !
Here is the description of my problem :
I have 3 classes on distinct file for each one :
- classA.ctl

Code: Select all

#uses "classB"
class classA {
	classB b;
};
- classB.ctl

Code: Select all

#uses "classC"
class classB {
	classC c;
};
- classC.ctl

Code: Select all

#uses "classA"
class classC {
	classA a;
};
And then when I use one of these classes, there is an error :

Code: Select all

CTRL, WARNING,    81, Syntax error, D:\WinCC_OA_Proj\FREJUSM3\scripts\libs\classC.ctl,   Line: 3
  classA a;
        ^
CTRL, WARNING,    81, Syntax error, D:\WinCC_OA_Proj\FREJUSM3\scripts\libs\classB.ctl,   Line: 3
class classB {
^
CTRL, WARNING,    81, Syntax error, D:\WinCC_OA_Proj\FREJUSM3\scripts\libs\classA.ctl,   Line: 3
class classA {
^
CTRL, WARNING,    81, Syntax error, D:\WinCC_OA_Proj\FREJUSM3\scripts\class.ctl,   Line: 2
#uses "classB"
^
This problem is known as circular dependency and it is resolved in C++ by using forward declaration, but it is not possible with WinCC OA 3.17.
Is there a smart way to solve this ?

amichon
Posts:93
Joined: Sat May 17, 2014 3:49 pm

Re: Circular dependency

Post by amichon »

Hi uxout ;)

Did you try with shared pointers ?

Code: Select all

class A
{
  public shared_ptr<void> ref;
};

class C
{
  public shared_ptr<void> ref;
};

main()
{
 shared_ptr<A> a = new A();
 shared_ptr<C> c = new C();

 a.ref = c;
 c.ref = a;
}

uxout
Posts:82
Joined: Wed Jul 20, 2016 12:07 pm

Re: Circular dependency

Post by uxout »

Hello amichon :D
Well that's not what I expected because you loose class reference but that's a point to look.
Maybe there is no correct solution and I should avoid this situation by doing code redesign.
Thanks anyway !

3 posts • Page 1 of 1