Hi,
I have two classes:
template <class Resourceclass GuardBase
{
protected :
Resource& fResource;
bool fAcquired;
GuardBase(Resource& res) : fResource(res), fAcquired(false) {}
public :
void acquire(void)
{
}
void release(void)
{
}
};
template <class Resourceclass LockGuard : public GuardBase<Resource>
{
public :
LockGuard(Resource& res) : GuardBase<Resource>(res)
{
fAcquired = false; // Error
fResource.acquire(); // Error
fAcquired = true;
}
~LockGuard()
{
if (fAcquired) // Error
fResource.release(); // Error
}
};
I get compiler errors for fAcquired (and fResource) "not declared in
this scope" in the constructor and destructor of LockGuard. This is
with G++ 4.1.0 on SUSE Linux. This previously compiled on several
other compilers.
Can someone tell me what is wrong here and how to fix it please?
TIA, Mark 8 1294
Mark wrote:
Hi,
I have two classes:
template <class Resourceclass GuardBase
{
protected :
Resource& fResource;
bool fAcquired;
GuardBase(Resource& res) : fResource(res), fAcquired(false) {}
public :
void acquire(void)
{
}
void release(void)
{
}
};
template <class Resourceclass LockGuard : public GuardBase<Resource>
{
public :
LockGuard(Resource& res) : GuardBase<Resource>(res)
{
fAcquired = false; // Error
fResource.acquire(); // Error
fAcquired = true;
}
~LockGuard()
{
if (fAcquired) // Error
fResource.release(); // Error
}
};
I get compiler errors for fAcquired (and fResource) "not declared in
this scope" in the constructor and destructor of LockGuard. This is
with G++ 4.1.0 on SUSE Linux. This previously compiled on several
other compilers.
Can someone tell me what is wrong here and how to fix it please?
Looks OK, try this->fAcquired.
--
Ian Collins.
Mark wrote:
template <class Resourceclass LockGuard : public GuardBase<Resource>
{
public :
LockGuard(Resource& res) : GuardBase<Resource>(res)
{
fAcquired = false; // Error
fResource.acquire(); // Error
fAcquired = true;
}
};
I get compiler errors for fAcquired (and fResource) "not declared in
this scope" in the constructor and destructor of LockGuard. This is
with G++ 4.1.0 on SUSE Linux. This previously compiled on several
other compilers.
Can someone tell me what is wrong here and how to fix it please?
This is due to changes which made g++ since 3.4 a lot more conformant to
the C++ standard. You have to make sure that names are treated as
dependent names, in this case by inserting this-as has been posted.
There are other cases requiring different handling. The corrected code
should be accepted by old compilers, at least gcc-3.3, too.
See http://gcc.gnu.org/gcc-3.4/changes.html
Bernd Strieder
Ian Collins wrote:
Mark wrote:
>Hi,
I have two classes:
template <class Resourceclass GuardBase { protected : Resource& fResource; bool fAcquired;
GuardBase(Resource& res) : fResource(res), fAcquired(false) {}
public :
void acquire(void) { }
void release(void) { }
};
template <class Resourceclass LockGuard : public GuardBase<Resource> { public : LockGuard(Resource& res) : GuardBase<Resource>(res) { fAcquired = false; // Error fResource.acquire(); // Error fAcquired = true; }
~LockGuard() { if (fAcquired) // Error fResource.release(); // Error } };
I get compiler errors for fAcquired (and fResource) "not declared in this scope" in the constructor and destructor of LockGuard. This is with G++ 4.1.0 on SUSE Linux. This previously compiled on several other compilers.
Can someone tell me what is wrong here and how to fix it please?
Looks OK, try this->fAcquired.
If does not look OK ...
You *have* to specify the "this->" if you want to use members inherited
from template classes, as if a base class is dependant on a template
parameter, its scope is not examine during unqualified name lookup (cf.
C++ norm 14.6.2 §3).
The reason is, if a specialisation of the template does not include
these members, what should the compiler do ? Look for these at global
scope ?
But the worst is the opposite: what if the child class uses some global
variables that happens to be public or protected members in some
specialization ? Not enforcing the "this->" could lead to very strange
behaviour !
Pierre
On Wed, 16 Aug 2006 11:33:03 +0200, Bernd Strieder
<st******@informatik.uni-kl.dewrote:
>This is due to changes which made g++ since 3.4 a lot more conformant to the C++ standard. You have to make sure that names are treated as dependent names, in this case by inserting this-as has been posted. There are other cases requiring different handling. The corrected code should be accepted by old compilers, at least gcc-3.3, too.
See
http://gcc.gnu.org/gcc-3.4/changes.html
Thanks to all who replied. This solves this problem ... now on to the
next ;-)
Mark
Pierre Barbier de Reuille wrote:
Ian Collins wrote:
>>Mark wrote:
>>>Hi,
I have two classes:
template <class Resourceclass GuardBase { protected : Resource& fResource; bool fAcquired;
GuardBase(Resource& res) : fResource(res), fAcquired(false) {}
public :
void acquire(void) { }
void release(void) { }
};
template <class Resourceclass LockGuard : public GuardBase<Resource> { public : LockGuard(Resource& res) : GuardBase<Resource>(res) { fAcquired = false; // Error fResource.acquire(); // Error fAcquired = true; }
~LockGuard() { if (fAcquired) // Error fResource.release(); // Error } };
I get compiler errors for fAcquired (and fResource) "not declared in this scope" in the constructor and destructor of LockGuard. This is with G++ 4.1.0 on SUSE Linux. This previously compiled on several other compilers.
Can someone tell me what is wrong here and how to fix it please? Looks OK, try this->fAcquired.
If does not look OK ...
You *have* to specify the "this->" if you want to use members inherited
from template classes, as if a base class is dependant on a template
parameter, its scope is not examine during unqualified name lookup (cf.
C++ norm 14.6.2 §3).
My understanding of that was the base class scope is used for name
lookup when the derived template class is instantiated.
--
Ian Collins.
Ian Collins wrote:
Pierre Barbier de Reuille wrote:
>Ian Collins wrote:
>>Mark wrote:
Hi,
I have two classes:
template <class Resourceclass GuardBase { protected : Resource& fResource; bool fAcquired;
GuardBase(Resource& res) : fResource(res), fAcquired(false) {}
public :
void acquire(void) { }
void release(void) { }
};
template <class Resourceclass LockGuard : public GuardBase<Resource> { public : LockGuard(Resource& res) : GuardBase<Resource>(res) { fAcquired = false; // Error fResource.acquire(); // Error fAcquired = true; }
~LockGuard() { if (fAcquired) // Error fResource.release(); // Error } };
I get compiler errors for fAcquired (and fResource) "not declared in this scope" in the constructor and destructor of LockGuard. This is with G++ 4.1.0 on SUSE Linux. This previously compiled on several other compilers.
Can someone tell me what is wrong here and how to fix it please?
Looks OK, try this->fAcquired. If does not look OK ... You *have* to specify the "this->" if you want to use members inherited from template classes, as if a base class is dependant on a template parameter, its scope is not examine during unqualified name lookup (cf. C++ norm 14.6.2 §3).
My understanding of that was the base class scope is used for name
lookup when the derived template class is instantiated.
It used to be like that for g++ (and most probably for many others) but
it was a mistake, as the norm explicitly says otherwise.
Pierre
Pierre Barbier de Reuille wrote:
Ian Collins wrote:
>>Pierre Barbier de Reuille wrote:
>>>Ian Collins wrote:
>>>>Looks OK, try this->fAcquired.
If does not look OK ... You *have* to specify the "this->" if you want to use members inherited from template classes, as if a base class is dependant on a template parameter, its scope is not examine during unqualified name lookup (cf. C++ norm 14.6.2 §3). My understanding of that was the base class scope is used for name lookup when the derived template class is instantiated.
It used to be like that for g++ (and most probably for many others) but
it was a mistake, as the norm explicitly says otherwise.
Um, it does too. Looks like the example contradicts the text, which
says the base class scope is not examined until the class template is
instantiated, which implies that it is included.
--
Ian Collins.
Mark <no****@nospam.spamwrote:
template <class Resourceclass GuardBase
{
protected :
Resource& fResource;
bool fAcquired;
GuardBase(Resource& res) : fResource(res), fAcquired(false) {}
public :
void acquire(void)
{
}
void release(void)
{
}
};
template <class Resourceclass LockGuard : public GuardBase<Resource>
{
public :
LockGuard(Resource& res) : GuardBase<Resource>(res)
{
fAcquired = false; // Error
fResource.acquire(); // Error
fAcquired = true;
}
~LockGuard()
{
if (fAcquired) // Error
fResource.release(); // Error
}
};
I get compiler errors for fAcquired (and fResource) "not declared in
this scope" in the constructor and destructor of LockGuard. This is
with G++ 4.1.0 on SUSE Linux. This previously compiled on several
other compilers.
Can someone tell me what is wrong here and how to fix it please?
Others have posted the solution using this->fAcquired, but there are
other workarounds too. See: http://www.parashift.com/c++-faq-lit...html#faq-35.18
--
Marcus Kwok
Replace 'invalid' with 'net' to reply This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael L. Hostbaek |
last post by:
Hi,
I am trying to compile a piece of software, on a FreeBSD system.
gcc version 2.95.4
When compiling, I get lots of these warnings:
---
logger.c: In function `cf_logger_init':
|
by: christopher diggins |
last post by:
I have posted a C# critique at
http://www.heron-language.com/c-sharp-critique.html. To summarize I bring up
the following issues :
- unsafe code
- attributes
- garbage collection
-...
|
by: SteveS |
last post by:
Hello All. I have an asp.net application with 3 different assemblies. They
are like this:
1) Assembly: PublicSite (This contains the website UI)
Root namespace: PublicSite
2) Assembly:...
|
by: Winista |
last post by:
I have a property in my class like..
Int32 iVal;
public String Val
{
get{return iVal;}
set{this.iVal = value;}
}
|
by: EoindeBarra |
last post by:
I am not sure where I am going wrong in the code below. It seems to be
working fine, then one of the pointers (directory1) gets garbage added
to it, and it breakes the rest of the program. Also,...
|
by: rohitkumar |
last post by:
this is my code to calculate the sum of digits in a number
for eg. 432567
sum =4+3+2+5+6+7=27
i 'm using turboc++ compiler from borland and i 'm runing my program on DOS.
...
|
by: brianrpsgt1 |
last post by:
Newbie here....
I have been able to successful pull info from a MySQL DB, get the
results and output them in an HTML format using Cheetah to the screen
using IDLE. I am doing this on a Windows...
|
by: Jeff |
last post by:
Hi
I'm trying to achieve a scenario where I have c# files that are compiled
dynamically, the assemblies are then loaded in a different AppDomain, I call
a simple method from the object, and then...
|
by: =?Utf-8?B?QWxleGFuZGVyIFd5a2Vs?= |
last post by:
My application is taking way too long to build. It use to never take so
long. I change only line and I think it recompiles all the classes in the
assembly because it hangs forever. Here is the...
|
by: Ed Leafe |
last post by:
I've noticed an odd behavior with compile() and code that does not
contain a trailing newline: if the last line is a comment inside of
any block, a syntax error is thrown, but if the last line is a...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |