Non-scalar type requested

Here's my constructor:

1
2
3
4
5
6
GuidedTour(string id, string description, double fee, int numBookings, string tourGuide, string theDate)
: Tour(id, description, fee) {
this->numBookings = numBookings;
this->tourGuide = tourGuide;
this->theDate  = theDate;
}

Here's the line of code in main to create a guided tour:

GuidedTour testTour = new GuidedTour("Test", "Test2", 100.00, 1, "Test3", "Test4");

Do you know why I get this error when I hit make?

1
2
3
4
5
6
> make
g++ -ansi -Wall -pedantic -o tour main.cpp tour.cpp tour.h guidedTour.cpp guidedTour.h
main.cpp: In function 'int main()':
main.cpp:34: error: conversion from 'GuidedTour*' to non-scalar type 'GuidedTour' requested
*** Error code 1
make: Fatal error: Command failed for target `tour' 
Last edited on
The left hand side is not a pointer but the right hand side is. Remove the word "new" and you're good to go.
I removed new and got this weird error:
1
2
3
4
5
6
7
8
9
10
> make
g++ -ansi -Wall -pedantic -o tour main.cpp tour.cpp tour.h guidedTour.cpp guidedTour.h
Undefined			first referenced
 symbol  			    in file
vtable for GuidedTour               /var/tmp//cclcunVb.o
ld: fatal: Symbol referencing errors. No output written to tour
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `tour'
>  
Last edited on
What version of gcc are you using?
g++ --version
Last edited on
1
2
3
4
5
> g++ --version
g++ (GCC) 4.3.1
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Can't change it by the way, our program has to compile on the university's system.
Last edited on
Ouch, 4.3.1 is horribly outdated (the latest is 4.8.1).

You should still compile with a more modern version to get better error messages that make more sense, then you can see if it compiles with the ancient version.

If you paste your source code in e.g. pastebin I can show you what the messages are from my compiler.

EDIT: You can also try ideone.com
Last edited on
Thanks, will PM.
Please don't do that. It's rude to PM (why should you get help but no one else?) and it's also rude to delete your posts.

I understand you don't want to post your code online but this is not the way to react.
Last edited on
Topic archived. No new replies allowed.