I am sure there is nothing wrong with this... I am racking my brain as to why it wont compile.

#include <iostream>
#include <string>

using namespace std;

class Vehicle {
		Vehicle(string m, int y);
		void print() const;
		string model;
		int year;

void Vehicle::print() const {
	cout << "Model = " << model << " , year = " << year << endl;

int main() {
	Vehicle a; //something extremely basic is moaning about this line
                   //if i use Vehicle a(); it seems to work but the rest of it has                                //problems because i used the parenthesis

the error is:

C:/Documents and Settings/Daryl/My Documents/159234/study1/inheritance.cpp:22: undefined reference to `Vehicle::Vehicle()'

Edited 6 Years Ago by Dazaa: n/a

It sounds like your compiler wants you to define the default constructor since you declared it and called it. The easiest response to this would be to add a set of curly brackets after the declaration of the default constructor and rebuild/run the program again.

Note that your program doesn't have the default constructor give the member variables any meaningful default values so calling print() object a will give junk for output, though it shouldn't stop compilation.

Edited 6 Years Ago by Lerner: n/a

This article has been dead for over six months. Start a new discussion instead.