I can't figure out what is wrong with following program. Would you
please help me? The error line is marked with error.
Peng
#include <iostream>
template <typename T>
class B{
public:
T t;
};
class A{
public:
template <typename T>
void doit(typename B<T> &b){//error
std::cout << "in " << std::endl;
}
};
int main(int argc, char *argv[])
{
B<int> b;
A a;
a.doit<int>(b);
} 5 1715 Pe*******@gmail .com wrote: void doit(typename B<T> &b){//error std::cout << "in " << std::endl; }
Take out the "typename" keyword.
Jacques. Pe*******@gmail .com wrote: I can't figure out what is wrong with following program. Would you please help me? The error line is marked with error.
Peng
#include <iostream>
template <typename T> class B{ public: T t; };
class A{ public: template <typename T> void doit(typename B<T> &b){//error
"error". Which error? Does your compiler just say "error" or
does it actually try to explain what it thinks is wrong?
Anyway, my compiler compiles it without a problem. It, of course
doesn't mean the code is fine. You need to remove the second
'typename' in this declaration. The line should be
void doit(B<T> &b) { // no "typename" here
std::cout << "in " << std::endl; } };
int main(int argc, char *argv[]) { B<int> b; A a; a.doit<int>(b); }
V
Victor Bazarov wrote: "error". Which error? Does your compiler just say "error" or does it actually try to explain what it thinks is wrong?
My compiler could certainly have been more helpful, IMHO. GCC 3.3 says
foo.cc:12: error: parse error before `&' token
It was good enough for me, but I can understand PengYu's confusion.
Jacques.
Jacques Labuschagne wrote: Victor Bazarov wrote: "error". Which error? Does your compiler just say "error" or does it actually try to explain what it thinks is wrong?
My compiler could certainly have been more helpful, IMHO. GCC 3.3 says foo.cc:12: error: parse error before `&' token It was good enough for me, but I can understand PengYu's confusion.
But imagine the compiler's confusion to run into the "typename" keyword
in what it thought was going to be a method declaration. At that point
the compiler has no idea what the programmer is trying to write, so it
has no idea which part of the expression the programmer should remove.
Greg
In article <11************ **********@z14g 2000cwz.googleg roups.com>,
Greg <gr****@pacbell .net> wrote: Jacques Labuschagne wrote: Victor Bazarov wrote: > "error". Which error? Does your compiler just say "error" or > does it actually try to explain what it thinks is wrong?
My compiler could certainly have been more helpful, IMHO. GCC 3.3 says foo.cc:12: error: parse error before `&' token It was good enough for me, but I can understand PengYu's confusion.
But imagine the compiler's confusion to run into the "typename" keyword in what it thought was going to be a method declaration. At that point the compiler has no idea what the programmer is trying to write, so it has no idea which part of the expression the programmer should remove.
You told it typename. It is believe you:
"ComeauTest .c", line 17: error: a class or namespace qualified name is required
void doit(typename B<T> &b){//error
(as per the rules of typename) or it doesn't.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris F Clark |
last post by:
In our C++ project we have some internal bug reporting macros that we
use to get useful information when the program does something
unexpected. Essentially at the point of the error, we invoke an
internal interactive debugger that knows the classes
within our system and allow us to walk around the objects that exist
at the time of the fault. It mostly works fairly well. That catch
being that we have to hand implement some of the code...
|
by: Lionel B |
last post by:
Greetings.
The following code compiles ok and does what I'd expect it to do:
---------- START CODE ----------
// test.cpp
|
by: Levent |
last post by:
Hi,
Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1):
#include <iostream>
template<class T, unsigned N>
struct Foo {
void func();
};
template<class T, unsigned N>
|
by: amparikh |
last post by:
I have something like this.
typedef enum TYPES{ X =0, Y,
Z,
MAX};
template <typename T>
class A
{
public:
|
by: pookiebearbottom |
last post by:
Just trying to learn some things about templates. Was wondering how
boost::tupple really works, but the headers were a bit confusing to me.
I know you get do something like the following, just want to know how
it works with the overloading of get<>().
boost::tupple<int,doubletup(1,2.0);
double d=tup.get<2>(); // equal 2.0
// simple set up,
| |
by: James Aguilar |
last post by:
Guys,
When I specialize a template class member function (I.e. a member
function of a template class) based on that class' type, bad things
happen. Here's some code:
---- test_header.h
#ifndef TEST_HEADER_H
#define TEST_HEADER_H
|
by: toton |
last post by:
Hi,
I want to specialize template member function of a template class .
It is creating some syntax problem ....
Can anyone say how to do it ?
The class is something like this
template<typename T,typename Alloc = std::allocator<T
class CircularBuffer4 {
public:
typedef typename CircularBuffer<T,Alloc>::size_type
|
by: stefan.bruckner |
last post by:
Hi,
I am looking for a way to achieve the following. I've tried a couple
of things, but they all ended up being too complicated:
I have a templated class A. I want another class B to be able to call
a method defined in A's base class which at runtime determines the
template parameters (I know ahead what is allowed) and calls a
templated member function B with A's template parameters.
|
by: StephQ |
last post by:
This is from a thread that I posted on another forum some days ago.
I didn't get any response, so I'm proposing it in this ng in hope of
better luck :)
The standard explanation is that pointer to functions are hard to
inline for the compiler, and so you won't be able to avoid function
call overhead.
This is an important aspect when you are calling a function very
frequently for evaluation reason: think of the problem of performing...
|
by: Barry |
last post by:
The following code compiles with VC8
but fails to compiles with Comeau online,
I locate the standard here:
An explicit specialization of any of the following:
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |