This code below compiles fine with VS.2005 but with gcc 3.4.2 not.
------------------
template<class T>
static void Wastage1D::clever_erase(vector<T> &v, vector<typename
vector<T>::iterator> &its, vector<T> &vo)
{ ........ }
------------------
I run gcc like this:
gcc -c wastage1d.cpp
The error message of gcc:
------------------
wastage1d.cpp:140: error: cannot declare member function `static void
wastage::Wastage1D::clever_erase(std::vector<T, std::allocator<_CharT> &, std::vector<typename std::vector<T, std::allocator<_CharT> ::iterator, std::allocator<typename std::vector<T,
std::allocator<_CharT> >::iterator> >&, std::vector<T,
std::allocator<_CharT> >&)' to have static linkage
wastage1d.cpp: In static member function `static void
wastage::Wastage1D::clever_erase(std::vector<T, std::allocator<_CharT>&, std::vector<typename std::vector<T, std::allocator<_CharT> ::iterator, std::allocator<typename std::vector<T,
std::allocator<_CharT> >::iterator> >&, std::vector<T,
std::allocator<_CharT> >&)':
------------------
What's wrong?
thanks for your time 7 4324
Chameleon wrote: This code below compiles fine with VS.2005 but with gcc 3.4.2 not. ------------------ template<class T> static void Wastage1D::clever_erase(vector<T> &v, vector<typename vector<T>::iterator> &its, vector<T> &vo) { ........ } ------------------
I run gcc like this: gcc -c wastage1d.cpp
The error message of gcc: ------------------ wastage1d.cpp:140: error: cannot declare member function `static void wastage::Wastage1D::clever_erase(std::vector<T, std::allocator<_CharT> >&, std::vector<typename std::vector<T, std::allocator<_CharT> >::iterator, std::allocator<typename std::vector<T, std::allocator<_CharT> >::iterator> >&, std::vector<T, std::allocator<_CharT> >&)' to have static linkage wastage1d.cpp: In static member function `static void wastage::Wastage1D::clever_erase(std::vector<T, std::allocator<_CharT> >&, std::vector<typename std::vector<T, std::allocator<_CharT> >::iterator, std::allocator<typename std::vector<T, std::allocator<_CharT> >::iterator> >&, std::vector<T, std::allocator<_CharT> >&)': ------------------
What's wrong?
It seems like you put 'static' not only on the member function
declaration, but on the definition too. Drop the one on the definition.
class C
{
static void f();
};
void C::f() // <-- no static here
{
}
Jonathan
Jonathan Mcdougall wrote: Chameleon wrote: This code below compiles fine with VS.2005 but with gcc 3.4.2 not. ------------------ template<class T> static void Wastage1D::clever_erase(vector<T> &v, vector<typename vector<T>::iterator> &its, vector<T> &vo) { ........ } ------------------
I run gcc like this: gcc -c wastage1d.cpp
The error message of gcc: ------------------ wastage1d.cpp:140: error: cannot declare member function `static void wastage::Wastage1D::clever_erase(std::vector<T, std::allocator<_CharT> >&, std::vector<typename std::vector<T, std::allocator<_CharT> >::iterator, std::allocator<typename std::vector<T, std::allocator<_CharT> >::iterator> >&, std::vector<T, std::allocator<_CharT> >&)' to have static linkage wastage1d.cpp: In static member function `static void wastage::Wastage1D::clever_erase(std::vector<T, std::allocator<_CharT> >&, std::vector<typename std::vector<T, std::allocator<_CharT> >::iterator, std::allocator<typename std::vector<T, std::allocator<_CharT> >::iterator> >&, std::vector<T, std::allocator<_CharT> >&)': ------------------
What's wrong?
It seems like you put 'static' not only on the member function declaration, but on the definition too. Drop the one on the definition.
class C { static void f(); };
void C::f() // <-- no static here { }
ok and thanks!
but I have one last problem (the same: VS.2005 does, gcc doesn't)
-------------------
template<class T>
void Wastage1D::clever_erase(vector<T> &v, vector<typename
vector<T>::iterator> &its, vector<T> &vo)
{
// ....... code .......
vector<T>::iterator cur = its.front(), curo = its.front();
vector<typename vector<T>::iterator>::iterator itscur = its.begin();
// ....... code .......
}
-------------------
gcc fails to compile with this message:
-------------------
wastage1d.cpp:148: error: expected `;' before "cur"
wastage1d.cpp:149: error: expected `;' before "itscur"
-------------------
how can I put ";" before "cur" or "itscur"?
after all these, I believe, for cross-platform code, its better to use
first gcc (until the completion of the program) and after VS.
thank you
Chameleon wrote: template<class T> void Wastage1D::clever_erase(vector<T> &v, vector<typename vector<T>::iterator> &its, vector<T> &vo) { // ....... code ....... vector<T>::iterator cur = its.front(), curo = its.front(); vector<typename vector<T>::iterator>::iterator itscur = its.begin(); // ....... code ....... } -------------------
gcc fails to compile with this message: ------------------- wastage1d.cpp:148: error: expected `;' before "cur" wastage1d.cpp:149: error: expected `;' before "itscur" -------------------
how can I put ";" before "cur" or "itscur"?
:)
Either you are inattentive or you didn't write part of the code because
the answer is right there :
vector<typename vector<T>::iterator>::iterator itscur
^^^^^^^^^^^
When a name depends on a template parameter, you must use typename to
indicate to the compiler that what follows is a type name and nothing
else. So your code becomes:
typename vector<T>::iterator cur = its.front(), curo = its.front();
typename vector<typename vector<T>::iterator>::iterator itscur =
its.begin();
after all these, I believe, for cross-platform code, its better to use first gcc (until the completion of the program) and after VS.
The more conforming the compiler is, the better, yes.
Jonathan
simpler sample:
---------------
#include <vector>
using namespace std;
template <class T> class c1 {
public:
static void c() {
vector<T>::iterator f;
}
};
int main() { c1<int> c; }
---------------
if I change for instance the line
vector<T>::iterator f;
with
vector<T> f;
works.
the error message:
--------------
test.cpp:7: error: expected `;' before "f"
--------------
Jonathan Mcdougall wrote: Chameleon wrote: template<class T> void Wastage1D::clever_erase(vector<T> &v, vector<typename vector<T>::iterator> &its, vector<T> &vo) { // ....... code ....... vector<T>::iterator cur = its.front(), curo = its.front(); vector<typename vector<T>::iterator>::iterator itscur = its.begin(); // ....... code ....... } -------------------
gcc fails to compile with this message: ------------------- wastage1d.cpp:148: error: expected `;' before "cur" wastage1d.cpp:149: error: expected `;' before "itscur" -------------------
how can I put ";" before "cur" or "itscur"?
:)
Either you are inattentive or you didn't write part of the code because the answer is right there :
vector<typename vector<T>::iterator>::iterator itscur ^^^^^^^^^^^
When a name depends on a template parameter, you must use typename to indicate to the compiler that what follows is a type name and nothing else. So your code becomes:
typename vector<T>::iterator cur = its.front(), curo = its.front(); typename vector<typename vector<T>::iterator>::iterator itscur = its.begin();
after all these, I believe, for cross-platform code, its better to use first gcc (until the completion of the program) and after VS.
The more conforming the compiler is, the better, yes.
it works! it works!
thanks a lot
Finally, the problem is that, I know only the basics about templates in
C++. The problem in above code, was only a symptom...
I must read.
Chameleon wrote: simpler sample:
--------------- #include <vector> using namespace std;
template <class T> class c1 { public: static void c() { vector<T>::iterator f; } };
int main() { c1<int> c; } ---------------
if I change for instance the line vector<T>::iterator f; with vector<T> f; works.
the error message: -------------- test.cpp:7: error: expected `;' before "f" --------------
Is that a question? If so, ask it plainly and remember to quote the
message are answering to.
The problem with the line
vector<T>::iterator f;
is that the compiler, at the time it sees this line, may be unable to
know what the definition of vector<> is for that specific T. Since
templates may be specialized, vector<A>::iterator could be a type and
vector<B>::iterator could be an object:
class A {};
class B {};
template <class T>
class vector;
template<>
class vector<A>
{
public:
typedef int iterator; // just an example
};
template<>
class vector<B>
{
public:
int iterator;
};
template <class T>
void f()
{
vector<T>::iterator itor; // what is 'iterator' here?
}
The language says that in this case, vector<T>::iterator sould be
considered as an object, not a type (it may be either one here,
depending on whether T is A or B). Adding 'typename' in front indicates
that 'iterator' is a type, not an object.
template <class T>
void f()
{
typename vector<T>::iterator itor; // 'iterator' is a type
}
As for using vector<T> directly, it poses no problem to the compiler
since that name must be declared before it is used. It is easy for the
compiler to decide whether it is a type or not.
Jonathan
Chameleon wrote: This code below compiles fine with VS.2005 but with gcc 3.4.2 not. ------------------ template<class T> static void Wastage1D::clever_erase(vector<T> &v, vector<typename vector<T>::iterator> &its, vector<T> &vo) { ........ } ------------------
I run gcc like this: gcc -c wastage1d.cpp
<snip>
Use 'gcc' to compile & link C code, and 'g++' to
compile & link C++ code. So...
g++ -c wastage1d.cpp
produces 'wastage1d.o' (or 'wastage1d.obj' on Windows?).
Than later, to link the executable 'wastage' (all on
one line - linux/unix example)...
g++ wastage1d.o other.o another.o -lsomelib -lanotherlib
-owastage
'g++' invokes the linker, passing it the correct options
and default libs. The syntax may differ slightly on Windows,
read the gcc/g++ docs.
Larry This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shlomi |
last post by:
Hi !
I've wrote quite a big code which bases on a considerable large amount
of template classes. (uses many different kinds of each template
class).
Now, without prior knowledge of mine, it turns out that this code
should
be compiled with compiler which doesn't support templates ! (OUCH!)
|
by: ik |
last post by:
Hello All,
Can somebody tell, which compiler conforms C++ Standard, regarding
templates better on Win32 Platform ? I was finding problems with
VC++6.0 with some template code, but the same works fine with Digital
Mars and Gcc. Is there any comparison available regarding templates for
these compilers ?
Any help will be appreciated.
Thanks
IK
|
by: Hafeez |
last post by:
I am having real trouble compiling this code
http://www.cs.wisc.edu/~vganti/birchcode/codeHier/AttrProj.tgz
The attachment shows errors when compiled using the current version of
g++ in a i386-pc-solaris2.9.
Seeing reference to gcc-2.7.2 in the Makefile of the code, I
downloaded it and compiled in my home directory. Then changed the...
|
by: pj |
last post by:
(Was originally, probably wrongly, posted to the vc subgroup.)
(This doesn't appear to be a c# problem, but a problem with a bug in
the Visual Studio c# compiler, but, any help will be welcome...)
Oh, I forgot to list the error messages; I would be delighted if
someone could explain how to deduce which line number in which file is
the one...
|
by: Darren Martz |
last post by:
Compiler: msvc 7.1
AppType: console
OS: WinXP Pro
I now get this "Internal Compiler Error mscl.cpp line 2701" message when I
build a specific project and cannot figure out why.
It was compiling fine, then I changed a resource text value and it started
complaining. I changed the code but it didn't matter, it now continually
complains.
| |
by: Steve |
last post by:
I have to develop several large and complex C++ hardware test programs that
should work under DOS, most likely with 32-bit DOS extender. Development
workstation OS would be Microsoft XP. Quite some time ago I worked in DOS,
with Borland BC++ 4.1. I do not have it any more. Which compiler would you
recommend me now? Which ones support serious...
|
by: Dixie |
last post by:
Is there a way to shell to Microsoft Word from Access and load a specific
template - using VBA?
dixie
|
by: Faheem Mitha |
last post by:
Hi,
The following bit of code compiles fine with gcc 3.3 or later, but has
problems with the Intel C++ compiler version 9.1, which produces the
following error message.
Is this a compiler bug, or is there something wrong with the code?
If the former, I'd be grateful for suggestions of a workaround, and if
the latter, please tell me...
|
by: Miroslaw Makowiecki |
last post by:
Where can I download Comeau compiler as a trial version?
Thanks in advice.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |