Multiple files in VS10

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 3628 Views - Last Post: 18 April 2010 - 09:27 PM Rate Topic: -----

#1 gibsonc22  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 06-March 10

Multiple files in VS10

Posted 18 April 2010 - 07:24 PM

This is the first time I have used mutiple files in C++ and I have a header and an incomplete implementation file.

This is the header
#ifndef CAR_H
#define CAR_H
#include <string>

class Car
{
private:
	int yearModel;
	string make;
	int speed;

public:
	Car(int, string);
	int getYearModel() const
		{ return yearModel; }
	string getMake() const
		{ return make; ;}
	int getSpeed() const
		{ return speed;}	
	void accelerate();
	void brake;
};
#endif


And this is what I have of the implementation file:
#include "Car.h"
#include <iostream>
#include <string>
using namespace std;

Car::Car(int year, string model)
{
     modelYear = year



I get an error with the Car::Car and the model because the comp does not know what they are.

Is This A Good Question/Topic? 0
  • +

Replies To: Multiple files in VS10

#2 KYA  Icon User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3199
  • View blog
  • Posts: 19,230
  • Joined: 14-September 07

Re: Multiple files in VS10

Posted 18 April 2010 - 07:43 PM

What's the exact error?
Was This Post Helpful? 0
  • +
  • -

#3 gibsonc22  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 06-March 10

Re: Multiple files in VS10

Posted 18 April 2010 - 07:47 PM

The first error is on the second car in Car::Car and is says "there is no instance of the overloaded function "Car::Car" matches the specified type

For modelYear and model is says they are undefined.

This post has been edited by gibsonc22: 18 April 2010 - 07:48 PM

Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3199
  • View blog
  • Posts: 19,230
  • Joined: 14-September 07

Re: Multiple files in VS10

Posted 18 April 2010 - 07:50 PM

In your definition it says yearModel, but in implementation is says modelYear.
Was This Post Helpful? 1
  • +
  • -

#5 gibsonc22  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 06-March 10

Re: Multiple files in VS10

Posted 18 April 2010 - 07:52 PM

I fixed the variables but I still get that error on the Car::Car
Was This Post Helpful? 0
  • +
  • -

#6 KYA  Icon User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3199
  • View blog
  • Posts: 19,230
  • Joined: 14-September 07

Re: Multiple files in VS10

Posted 18 April 2010 - 07:55 PM

Full and updated code listing please.


Also 14,000th post sweeeeeeeeet
Was This Post Helpful? 1
  • +
  • -

#7 gibsonc22  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 06-March 10

Re: Multiple files in VS10

Posted 18 April 2010 - 07:59 PM

this is Car.cpp
#include "Car.h"
#include <iostream>
#include <string>
using namespace std;

Car::Car(int year, string car)
{
     yearModel = year;
	 make = carMake;
	 speed = 0;
}



This is Car.H
#ifndef CAR_H
#define CAR_H
#include <string>
class Car
{
private:
	int yearModel;
	string make;
	int speed;

public:
	Car(int, string);
	int getYearModel() const
		{ return yearModel; }
	string getMake() const
		{ return make; ;}
	int getSpeed() const
		{ return speed;}	
	void accelerate();
	void brake;
};
#endif



Congrats on the post.
Was This Post Helpful? 0
  • +
  • -

#8 KYA  Icon User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3199
  • View blog
  • Posts: 19,230
  • Joined: 14-September 07

Re: Multiple files in VS10

Posted 18 April 2010 - 07:59 PM

Car::Car(int year, string car)
{
     yearModel = year;
         make = carMake;
         speed = 0;
}




carMake isn't defined or declared anywhere. Did you mean to assign it to the parameter 'car'?
Was This Post Helpful? 0
  • +
  • -

#9 gibsonc22  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 06-March 10

Re: Multiple files in VS10

Posted 18 April 2010 - 08:03 PM

Car::Car(int year, string car) is supposed to be a constructor to set the initial values of instances of Car that are created.
Was This Post Helpful? 0
  • +
  • -

#10 KYA  Icon User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3199
  • View blog
  • Posts: 19,230
  • Joined: 14-September 07

Re: Multiple files in VS10

Posted 18 April 2010 - 08:07 PM

Right and you're assigning a non existent variable to your data.
Was This Post Helpful? 0
  • +
  • -

#11 gibsonc22  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 06-March 10

Re: Multiple files in VS10

Posted 18 April 2010 - 08:10 PM

Oh I see what you mean I changed it to
Car::Car(int year, string carMake)


Still get that Car:Car error.
1 IntelliSense: no instance of overloaded function "Car::Car" matches the specified type c:\users\bill\documents\visual studio 2010\projects\wjhunit12car\wjhunit12car\car.cpp 6
Was This Post Helpful? 0
  • +
  • -

#12 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Multiple files in VS10

Posted 18 April 2010 - 08:24 PM

g++ reports this:

Car.h:20: error: variable or field ‘brake’ declared void


which I figured. That should be a function.

Other than that it compiles.

Quote

24 User(s) are reading this topic
4 members, 20 guests, 0 anonymous users


Off-topic, WTF??? You have your whole class here?

EDIT: Ahhh...maybe this is it...it's not a compiler error...it's an INTELLISENSE error!!

Quote

1 IntelliSense: no instance of overloaded function "Car::Car" matches the specified type c:\users\bill\documents\visual studio 2010\projects\wjhunit12car\wjhunit12car\car.cpp 6


How about you give your prototype actual argument names, see if that helps!
Was This Post Helpful? 1
  • +
  • -

#13 gibsonc22  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 06-March 10

Re: Multiple files in VS10

Posted 18 April 2010 - 08:35 PM

No , still the same.
Was This Post Helpful? 0
  • +
  • -

#14 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Multiple files in VS10

Posted 18 April 2010 - 08:43 PM

I do not have VS 2010 installed, so I can't be of much assistance with that specifically. The fact that INTELLISENSE is part of that error is somehow important. You can try running "Clean Solution" and "Rebuild Solution" to see if the IntelliSense database gets rebuilt. You could try closing VS and reopening it as well.

Also, perhaps this might be the same issue?
Was This Post Helpful? 0
  • +
  • -

#15 gibsonc22  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 06-March 10

Re: Multiple files in VS10

Posted 18 April 2010 - 08:48 PM

when I rebuild I got a lot of strange errors like this one in the header file for

string make;

Error 1 error C2146: syntax error : missing ';' before identifier 'make' c:\users\bill\documents\visual studio 2010\projects\wjhunit12car\wjhunit12car\car.h 8

Why would I need a semicolon there!

I moved the class from the header to the cpp and the error went away. Do I have to do anything to link the files somehow?

This post has been edited by gibsonc22: 18 April 2010 - 08:50 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2