Scope of file in classes

Hi everyone,

I am not so experienced in OOP, maybe that’s why I have following problem:

I wrote a programm that uses 2 classes. In both classes I access the same file, so I put the file definition in both class modules - between member() and code.

But after compiling the linker complains about „duplicate symbol“, because the file definition occurs in both classes.

I tried to remove the file from the class modules and put it into the main PROGRAM source.
But then the compiler comes up with „unknown identifier“ and „no matching prototype available“ when accessing the file.
… what I honestly don’t understand because I made the file „global“. The scope of a global file definition doesn’t seem to reach into the class object. But okay, this was just an attempt to understand the compiler’s logic – vain endeavor :wink:

Maybe someone can enlighten me, where would be the best place to define files when using them in many procedures seperatly? (I don’t think this is a pure OOP problem)

Thanks for a hint!
Regards, Torsten

Hi Torsten,

The reason your module isn’t seeing the global data is the member statement.

A module needs a member statement
There are two kinds, one with a filename, one without
I call the ones without a file name, an empty member statement.

MEMBER() ! empty member statement

When a module has an empty member statement, it’s all by itself, it has no shared scope.
This also means that the module can then be used by multiple programs.

So in your classes, what do you need to do with the file?
Can you use just a generic file, which can be passed in, leaving the class more generically useful ?
Or do you need to know more details about the file itself?

Your problem is probably related to my PTSS: 39274 from 2012.

If you have any similarly named variables between modules, you will get a dupe symbol.

Here’s the example,w hich seems to be missing from my ptss (1.9 KB)

Hi Mark,

I recently changed the program the way you suggest and it works now. In parallel I switched from oop to procedural, so the program is then clearer for me.
Thank you so much for your valuable help!

Still it’s weird for me why the compiler spits out “duplicate symbol” for file definitions used in two classes with the member() statement. Both definitions should have their own scope afaik. But I quit searching for an explaination - as long as it works now.

Hi, thanks for the good example - as it shows exactly what I am doing in my program.
The peculiarity is that I use the same file in both classes. The compiler/linker tells me then “duplicate symbol” what is contrary to my understanding about the scope of files or variables.
But as I already told Mark, the most important thing is that I have a viable solution.

I guess the most viable solution is not to do it how you’re doing it.

Who knows when/if this would ever get fixed.