User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,571 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,617 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2899 | Replies: 2
Reply
Join Date: Sep 2007
Posts: 14
Reputation: hectic is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
hectic hectic is offline Offline
Newbie Poster

expected init-declarator

  #1  
Oct 28th, 2007
hi i have used the template in my simulation program but it generate the error, my program line of code that generate the error is (these code are in queue.template file)

template <class QueueItem>
queue <QueueItem>::~queue() // line25
{

}

template <class QueueItem>
void queue<QueueItem>::push(const QueueItem& entry) //line 42
{

}

template <class QueueItem>
std::ostream& operator << (std::ostream& out_s, const queue<QueueItem>& q)
{
typename queue<QueueItem> ::Node *QueueCursor; // line 85
// code here
}

ERROR generated are
queue.template:25: error: expected constructor, destructor, or type conversion before '<
queue.template:25: error: expected `;' before '<' token
queue.template:42: error: expected init-declarator before '<' token
queue.template:42: error: expected `;' before '<' token

queue.template:84: error: ISO C++ forbids declaration of `queue' with no type
queue.template: In function `std::ostream& CSCI30l_queue::operator<<(std::ostream&, int)
queue.template:85: error: expected nested-name-specifier before "queue"
queue.template:85: error: expected `(' before '<' token
queue.template:85: error: expected primary-expression before '>' token
queue.template:85: error: `::Node' has not been declared
queue.template:85: error: `QueueCursor' undeclared (first use this function)
queue.template:85: error: (Each undeclared identifier is reported only once for each fun )
queue.template:86: error: `q' undeclared (first use this function)

I could not figure out the problem

here the queue is the class that have the constructor and class itself defined in the queue.h file and this queue.template file is the implementation of the member function defined in the queue.h file
Last edited by hectic : Oct 28th, 2007 at 10:37 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: expected init-declarator

  #2  
Oct 28th, 2007
Your syntax needs help. See the C++ FAQ Lite.

The difference between a regular class or function and a template class or function is just that you have
template<typename Foo>
in front of it, and can use Foo as a generic type instead of a specific type like int, or string or somesuch.

So:
  1. //print an array of ints
  2. void printa( int a[], int len ) {
  3. for (int i = 0; i < len; i++)
  4. std::cout << a[ i ] << std::endl;
  5. }
can be made to print any printable thing by turning it into a template function:
  1. //print an array of any printable thing
  2. template<typename PrintableThing>
  3. void printa( PrintableThing a[], int len ) {
  4. for (int i = 0; i < len; i++)
  5. std::cout << a[ i ] << std::endl;
  6. }
Now I can print arrays of strings, floats, etc...

Compare the difference between the two functions, read your textbook over again, and look at the C++ FAQ Lite page I gave you. Also, use the word "typename" instead of "class" in your template declarations.

Hope this helps.
Last edited by Duoas : Oct 28th, 2007 at 11:43 pm.
Reply With Quote  
Join Date: Sep 2007
Posts: 14
Reputation: hectic is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
hectic hectic is offline Offline
Newbie Poster

Re: expected init-declarator

  #3  
Oct 29th, 2007
i do not find error in my code, what u are trying to tell is right, i have the same rule follows, i have gone through the michael main, 'data structure and other objects using C++",
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC