Hi all,
I have C++ source code that compiles on windows-MS VS2005 without any problem. I am trying to compile it in Linux gcc version 4.1.2 (Ubuntu 4.1.2-0ubuntu4) and I ran into the following compiler error:
error: expected template-name before ‘<’ token
error: expected `{' before ‘<’ token
error: expected unqualified-id before ‘<’ token
(the error points to the line containing class myMarchingSurface3D:public CMarchingSurface3D<U> in the derived class)
I have looked in other threads and it seems inheritance with template classes gives some portability problems. I attach the code here: - template<class U>
-
class CMarchingSurface3D
-
{
-
[...other methods]
-
public:
-
inline virtual CVector3D<TV3DFLOAT> GetVoteDir(CPoint3D<INT16> &p, CTokenGroup3D<U>& tokengroup) { return CVector3D<TV3DFLOAT>(0,0,0); }
-
-
}
-
-
// implement the virtual functions here for
-
// marching surface.
-
class myMarchingSurface3D:public CMarchingSurface3D<U>{
-
public:
-
-
[...othe rmethods]
-
inline CVector3D<TV3DFLOAT> GetVoteDir(CPoint3D<INT16>& p, CTokenGroup3D<U>& tokengroup) {
-
//collect the the stick vote from neighbour
-
CTensorVote3D<TV3DFLOAT> vote=
-
m_kernal->GetAllStickVotesTensor(p,tokengroup,*m_stickfield);
-
vote.Split();
-
// we use the sqrt(Lambda1)-sqrt(Lambda2) for voxel strength
-
m_lastSal=sqrt(vote.GetLambda1())-sqrt(vote.GetLambda2());
-
return vote.GetE1();
-
}
-
};
Thanks for your help in advance,
Fernando
10 29074
class myMarchingSurface3D:public CMarchingSurface3D<U>{
public:
[...othe rmethods]
You need to declare this class as a template to support inheriting from CMarchingSurface3D<U>. Otherwise, the compiler thinks U is a real type: -
template <class U>
-
class myMarchingSurface3D:public CMarchingSurface3D<U>{
-
public:
-
-
[...othe rmethods]
-
Also, there are no inline virtual functions. Virtual functions have their addresses kept in a virtual function table (VTBL) to support polymorphism.
Inline functions are merely copied inline where they are called. They don't have addresses. Since C++ sees the inline keyword as a suggestion by you, it doesn't necessarily have to agree to it. In this case, the inline is ignored in favor of the virtual keyword.
Personally, I would remove the inline keyword from the templates.
You need to declare this class as a template to support inheriting from CMarchingSurface3D<U>. Otherwise, the compiler thinks U is a real type: -
template <class U>
-
class myMarchingSurface3D:public CMarchingSurface3D<U>{
-
public:
-
-
[...othe rmethods]
-
Also, there are no inline virtual functions. Virtual functions have their addresses kept in a virtual function table (VTBL) to support polymorphism.
Inline functions are merely copied inline where they are called. They don't have addresses. Since C++ sees the inline keyword as a suggestion by you, it doesn't necessarily have to agree to it. In this case, the inline is ignored in favor of the virtual keyword.
Personally, I would remove the inline keyword from the templates.
Hi,
Thanks for the quick reply and the tips. I added template<class U> as suggested but I still get the same error from the gcc compiler. Any idea what can be the problem?
Thanks,
Fernando
No. I got it to compile using Visual Studio.NET 2005. I know very little about gcc. I assume you are compiling as g++ to get the C++ compiler?
No. I got it to compile using Visual Studio.NET 2005. I know very little about gcc. I assume you are compiling as g++ to get the C++ compiler?
Hi,
Yes, I am using g++. The problem seems to be somehow with the standards. As I said in my first post I compile without any problem using MS-VS. However, GNU gcc wants things different. But after trying many different things I don't know how to put them different. Any suggestion?
Thanks,
Fernando
I fixed a similar problem by templating with -
template<typename U>
-
class A {
-
Using typename rather than class or classname seems to make g++ happier for some reason...
I fixed a similar problem by templating with -
template<typename U>
-
class A {
-
Using typename rather than class or classname seems to make g++ happier for some reason...
Hi,
Where do I have to change template<class U> by template<typename U>? Everywhere (in all the .cpp implementing the methods for teh template class?)? What is the difference between typename and class?
I tried to change class U by typename U only in the declaration and teh compiler still gives the same error.
Thanks,
Fernando
Everywhere you have template<class U>, change it to template<typename U>.
I can't guarantee this will work, but I've had success with it, as the book I learned from used <classname U> and that gave me errors until I switched to typename.
Everywhere you have template<class U>, change it to template<typename U>.
I can't guarantee this will work, but I've had success with it, as the book I learned from used <classname U> and that gave me errors until I switched to typename.
Hi,
I tried to change it everywhere and still gives the same error. However, the code compiles with gcc-3.3.5 (I just tried it) but not with gcc-4.1.2. Any idea what happens? This is very frustrating:(
Thanks,
Fernando
Frankly, I can't tell you any more, though I have had some issues with templates on later versions of gcc.
Everywhere you have template<class U>, change it to template<typename U>.
I can't guarantee this will work, but I've had success with it, as the book I learned from used <classname U> and that gave me errors until I switched to typename.
class U and typename U are equivalent. typename is generally used by template writers whio are not using classes.
There is no such thing as classname. That is a synrtax error.
On g++, has anyone tried the -pedantic switch? That disables non-ANSI extensions to C++.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: shank |
last post by:
I'm getting an Expected 'End' error on the following.
What did I forget?
<%
p = rsSpecs("OrderNo") & chr(13) & chr(10)
p = p & rsSpecs("Description") & chr(13) & chr(10)
p = p & media &...
|
by: Matt |
last post by:
When the ASP statement end with a _ character, then the next line cannot
have comment ' character. Is that correct? Since I encountered the following
error:
Microsoft VBScript compilation...
|
by: Squid Seven |
last post by:
This is just bizarre. for the following snippet of code:
#include <string>
using std::string;
I get the error message:
|
by: David Cook |
last post by:
The html file below gets intermittent errors 'error on page' ('number
expected')
when clicking on column-headings to sort. Yet, this same file works
flawlessly
in other browsers (i.e. Opera,...
|
by: undercups |
last post by:
When I run page I immediatley get "Object expected" message and the tag
<body onload="setfocus()" is highlighted.
The error occurs in this snippet from within the script file
function...
|
by: Sameers (theAngrycodeR) via .NET 247 |
last post by:
I think I will get MAD very soon. Its very weired problem I amfacing here. Let me explain.
I have two DBF files from which I want to export data in CSVformat. I created a desktop application and...
|
by: liam |
last post by:
Hi,
I have seen this problem is a couple of other places in the group but
can't find an answer to it.
Basically I have as aspx file that opens properly in Opera but not in
IE. IE gives a...
|
by: Mark |
last post by:
I have written a PocketPC application that connects to a web service, and
when im connected via the cable or via wireless then it pulls back the data
correctly.
However when connected to GPRS, i...
|
by: JOJO123 |
last post by:
I got here in search of an answer to this Javascrpt question. I upgraded jave on XP Ie 7, acrobat 5.1 and suddenly can't open any pdf files on web sites using IE.
I see u guys all say, this is a...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |