Strange access/scope resolution errors

A

Alfonso Morra

I have some code that I am porting over from C. It is full of static
functions and global variables. I have got around this by wrapping most
of the code in a singleton object.

However, I am findng that in my method definitions, I am having to fully
scope the names of any other functions I am calling. I do not understand
this. The clas declaration code look some thing like this:

class A: public Singleton<A> {
public:
A();
~A() ;

private:
A (const A&)

struct1 x ;
int b ;
........
foo1() ;
foo2() ;
};


The implementation looks like this:

A::foo1() {
foo2() ; // <- compiler coplains here (dosent know about fo2
....
}

The actual compiler error msg is:
error C3861: 'foo2': identifier not found, even with argument-dependent
lookup.

However, this works:

A::foo1() {
A::foo2() ; // <- compiler coplains here (dosent know about fo2
....
}

Why?. I have never had to explicitly name functions before, and these
are uniquely named functions. Thanks
 
J

John Carson

Alfonso Morra said:
I have some code that I am porting over from C. It is full of static
functions and global variables. I have got around this by wrapping
most of the code in a singleton object.

However, I am findng that in my method definitions, I am having to
fully scope the names of any other functions I am calling. I do not
understand this. The clas declaration code look some thing like this:

class A: public Singleton<A> {
public:
A();
~A() ;

private:
A (const A&)

struct1 x ;
int b ;
........
foo1() ;
foo2() ;
};

The implementation looks like this:

A::foo1() {
foo2() ; // <- compiler coplains here (dosent know about fo2
....
}

The actual compiler error msg is:
error C3861: 'foo2': identifier not found, even with
argument-dependent lookup.


I don't believe this. Present some real compileable code that shows the
error (I have a suspicion what your real code looks like, but we shouldn't
have to guess).
 
A

Alfonso Morra

John said:
I don't believe this. Present some real compileable code that shows the
error (I have a suspicion what your real code looks like, but we
shouldn't have to guess).

I can understand your incredulity. This had me baffled for most part of
the day yesterday. I am quite sure that I'm doing something that is
quite simply, foolish - but I probably need a another set of eyes to
point this out/spot the error.

There is too much code to post here, The following is a much, much
abridged version (I have removed the Singleton inheritance - to simplify
the code - the errors still occur):



class SharedMemory {
private:
//definition of internal structures
// required in other struct definitions later
typedef struct _sys {...} SYSTEM ;
typedef struct _bny {...} BARNEY ;

public:
typedef struct _slice {...} POOL_SLICE ;
typedef struct _hdr {...} POOL_HEADER ; //has member of type SYSTEM
static enum { ... }SLICE_TYPES ; //'static' keyword hack to get code
to compile, bcos I needed to
initialize an element.

private:
//Prevent copy and assignement
SharedMemory(const SharedMemory&) ;
SharedMemory& operator=( const SharedMemory&) ;
typedef struct _sem{ ... } SEMAPHORE ;
typedef struct _lcpy{ ...} LOCAL_COPY ;

/* Private var */
int var1 ;
POOL_HEADER* hdr ;
LOCAL_CPY *shmcpy ;
.....

/* private methods */
POOL_HEADER *get_header() ;
POOL_SLICE *get_slice() ;
int foobar() ;
...
};


Implemenntation:

SharedMemory::pOOL_Header* SharedMemory::getHeader() {
int a = foobar(); //I need an explicit name here!
return hdr ; // causes errors:
(1). needs explicit name SharedMemory::hdr
(2). after name change, compiler complains: "illegal
reference to non-static member SharedMemory::hdr'"
}


Another thing I forgot to mention in my earlier post was that I cannot
also, reference (private) local variables (e.g. var1), without either a
fully resolved name (i.e. SharedMemory::var1), or by using the 'this'
pointer (e.g. this->var1). This is quite strange, as I have never come
accross this before, and it is also making the code quite unreadable.

Any ideas, suggestions will be welcome.

Tks
 
A

Alfonso Morra

Alfonso said:
I can understand your incredulity. This had me baffled for most part of
the day yesterday. I am quite sure that I'm doing something that is
quite simply, foolish - but I probably need a another set of eyes to
point this out/spot the error.

There is too much code to post here, The following is a much, much
abridged version (I have removed the Singleton inheritance - to simplify
the code - the errors still occur):



class SharedMemory {
private:
//definition of internal structures
// required in other struct definitions later
typedef struct _sys {...} SYSTEM ;
typedef struct _bny {...} BARNEY ;

public:
typedef struct _slice {...} POOL_SLICE ;
typedef struct _hdr {...} POOL_HEADER ; //has member of type SYSTEM
static enum { ... }SLICE_TYPES ; //'static' keyword hack to get code
to compile, bcos I needed to
initialize an element.

private:
//Prevent copy and assignement
SharedMemory(const SharedMemory&) ;
SharedMemory& operator=( const SharedMemory&) ;
typedef struct _sem{ ... } SEMAPHORE ;
typedef struct _lcpy{ ...} LOCAL_COPY ;

/* Private var */
int var1 ;
POOL_HEADER* hdr ;
LOCAL_CPY *shmcpy ;
.....

/* private methods */
POOL_HEADER *get_header() ;
POOL_SLICE *get_slice() ;
int foobar() ;
...
};


Implemenntation:

SharedMemory::pOOL_Header* SharedMemory::getHeader() {
int a = foobar(); //I need an explicit name here!
return hdr ; // causes errors:
(1). needs explicit name SharedMemory::hdr
(2). after name change, compiler complains: "illegal
reference to non-static member SharedMemory::hdr'"
}


Another thing I forgot to mention in my earlier post was that I cannot
also, reference (private) local variables (e.g. var1), without either a
fully resolved name (i.e. SharedMemory::var1), or by using the 'this'
pointer (e.g. this->var1). This is quite strange, as I have never come
accross this before, and it is also making the code quite unreadable.

Any ideas, suggestions will be welcome.

Tks

Not to worry. I've now fixed the problem. error messages turned out to
be a bit of a red herring ..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top