Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Template question. I really do not understand what this wants....

Posted on 2006-11-06
3
Medium Priority
?
238 Views
Last Modified: 2010-04-01
OK. I have a Template....
template<typename T>        

class LookupTable2
{
  public:
    LookupTable2 (void);
 
    unsigned int getRows (void) const;    

 private:
    std::vector<std::vector<T> > table2_; ///< Create table object.
 };

Then I have another class that inherits the above....

};

#include "LookupTable2.h"

#include <iostream>
#include <vector>
#include <cmath>
template<typename T>            

class LookupTable3 : public LookupTable2 <T>
{
  public:
    LookupTable3<T> (void);
    void printAttributes (void);
 
  private:
    std::vector<LookupTable2<T> > table3_;  // Create table object.
 
};


Then I have a main() in a driver

#include <iostream>

#include "LookupTable3.h"
using namespace std;


int main (void)
{
  unsigned int nRow, nCol;

  LookupTable2<float> table2iv();
   
  table2iv.getColumns();

  LookupTable3<float> table3iv();

  table3iv.printAttributes();

  return 0;
}


I am getting an error in both

  table2iv.getColumns();

  LookupTable3<float> table3iv();

in the main. The error is   error C2228: left of '.getColumns' must have class/struct/union type

What is this asking. I do not understand.....Can some one tell me what?
0
Comment
Question by:prain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
wayside earned 300 total points
ID: 17885272
>   LookupTable2<float> table2iv();
 
This is declaring a function that returns a LookupTable2<float> object, it is not declaring an object and calling the default constructor.

Get rid of the ()'s:

  LookupTable2<float> table2iv;
  LookupTable3<float> table3iv;

0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question