error LNK 2019

a class inherited form another class
the book call in an exercise that we need to design a class carType, ihnerited from the class dealer.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  class carType : public dealer
{
carType:: carType();
carType::carType (string model, string manufact): dealer ( model, manufact)
carType::carType( getModel)
{
return model
}
carType::carType ( setModel)
{
model= mdl;
}
// is this is correct?
//Why i'm getting the error LNK 2019?
}
what is the actual error message?
is it c++?
if so, why are you using carType when constructors are in the class?
in line 4 replace : w/ ;
place a ; at the end of line 7
in line 4 replace : w/ ;

i disagree with this. He/she is trying to initialise base class members I think (like this: http://learningcppisfun.blogspot.co.uk/2007/11/initialization-lists-and-base-class.html ).

(but i'm not sure why the OP is reporting linker errors when the compilation errors should be stopping it).
Last edited on
He/she is trying to initialise base class members


@mutexe ,
constructors are not inherited, so your assumption is wrong.

and @alex6es,
what is dealer() is in line 4?
constructors are not inherited, so your assumption is wrong.

look at the link i posted. and learn something new.
@mutexe:

FYI, your link behaves as if it's badly formed, because the forum software considers the closing bracket and full-stop as if they're part of the URL, and so includes them in the link.

If you edit it to add whitespace between the actual URL and the closing bracket, it will be properly clickable.

EDIT: Regarding the OP's question - you don't need to prefix method names with ClassName:: when you're declaring/defining them inside the class definition. The ClassName:: is automatically assumed, because you're already inside class ClassName { ... }.
Last edited on
@mutexe
the page you suggested doesn't inherit constructor
FYI, your link behaves as if it's badly formed, because the forum software considers the closing bracket and full-stop as if they're part of the URL, and so includes them in the link.


Oops, thanks for that Mikey.

the page you suggested doesn't inherit constructor

i didnt say it did?
@ aalok
why are you using carType when constructors are in the class?

could you explain me that?

@ world
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 class className : public NameType; // is this the correct initialization to inherited a class from a class ? 
{
// constructor
className : : className();
// gettters
className : : getName()
{
   return firstName;
}
// settters
className : : setName(string name )
{
   firstName= name;
}

}


no.
there is no semi-colon at the end of line 1.
you need to add a semi-colon at the end of your class declaration. (line 16)
Your getName() method must have a return type.
The scope resolution operator is '::' i.e. no space inbetween them.
you need to declare firstname as a member variable of your class.

and as poeple keep telling you, if you are putting the method implementations inside your class you DO NOT need "class::" prefixes.

something like this is ok i think:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37


#include<string>

class NameType
{
	
};


class className : public NameType 
{
public:
	className();

	std::string getName()
	{
		return firstName;
	}

	void setName(std::string name )
	{
		firstName= name;
	}

private:
	std::string firstName;
};

int main()
{
	// stuff

	return 0;
}


Last edited on
Thanks!
I was missing line 5.Thanks for the advise!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<string>

class NameType
{
	NameType();
};


class className : public NameType 
{
public:
	className();

	std::string getName()
	{
		return firstName;
	}

	void setName(std::string name )
	{
		firstName= name;
	}

private:
	std::string firstName;
};

int main()
{
	// stuff

	return 0;
}

@alex6es
EDIT: Regarding the OP's question - you don't need to prefix method names with ClassName:: when you're declaring/defining them inside the class definition. The ClassName:: is automatically assumed, because you're already inside class ClassName { ... }.

here is the answer to ur ques by mikey boy
Topic archived. No new replies allowed.