error LNK 2019

Dec 9, 2013 at 2:59pm
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?
}
Dec 9, 2013 at 3:42pm
what is the actual error message?
Dec 9, 2013 at 3:49pm
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
Dec 9, 2013 at 4:36pm
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 Dec 10, 2013 at 8:32am
Dec 9, 2013 at 4:52pm
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?
Dec 9, 2013 at 4:59pm
constructors are not inherited, so your assumption is wrong.

look at the link i posted. and learn something new.
Dec 9, 2013 at 6:00pm
@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 Dec 9, 2013 at 6:02pm
Dec 10, 2013 at 7:35am
@mutexe
the page you suggested doesn't inherit constructor
Dec 10, 2013 at 8:32am
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?
Dec 10, 2013 at 1:23pm
@ 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;
}

}


Dec 10, 2013 at 2:43pm
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 Dec 10, 2013 at 2:43pm
Dec 10, 2013 at 6:09pm
Thanks!
Dec 10, 2013 at 11:36pm
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;
}

Dec 11, 2013 at 12:56pm
@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.