I have a Feature
class which has a public vehicle_type
in it and I have 3 candidates for vehicle_type
variable which are; Car
,Truck
and Motor
classes. When I call constructor for Feature
class, well I want my program to get which vehicle type was called with constructor automatically. I actually tried to use Templates
for the problem but it didn't work. So, can someone tell me how to achieve this with or without using Templates
.
This is my Feature.h
file:
#ifndef FEATURE_H
#define FEATURE_H
#include <string>
#include "../includes/Car.h"
#include "../includes/Truck.h"
#include "../includes/Motor.h"
template <typename T>
class Feature{
public:
Feature();
Feature(int w, std::string b, std::string clr, double p, T v_t);
T vehicle_type;
int wheels;
std::string brand;
std::string color;
double price;
};
#endif
This is my Feature.cpp
file:
# include "../includes/Feature.h"
template <typename T>
Feature::Feature(int w, std::string br, std::string clr, double p, T v_t){wheels = w; brand=br; color = clr; price=p; vehicle_type = v_t; }
Feature::Feature(){}
and lastly, this below is the error occurs when I hover my mouse on Feature
constructor in the Feature.cpp
file.
name followed by '::' must be a class or namespace name
Feel free to ask for more information. Thanks.