Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Tomed2000
Jun 24, 2002

I've just started getting back into C++ and I've been coding small console apps with Visual C++ 2008 Express and I keep running into weird linking problems while building my projects.

Note that I usually have a header file (.h) and the definitions file (.cpp) for my class then a separate driver file for main. I was testing out program in the driver when I found out that I needed to modify the class. I do a few changes and then I go back to building the project and I get weird runtime errors. I step through the code and notice that the changes I made didn't take.

I try a bunch of stuff like closing/opening the program, rebuilding the project, etc but I finally delete all of the project files created by VC++, create a new project adding my file back in, and it finally works.

Is this a common problem or am I doing something wrong? Should I be using a difference compiler?

Tomed2000 fucked around with this message at 17:23 on Apr 9, 2009

Adbot
ADBOT LOVES YOU

Tomed2000
Jun 24, 2002

Alright.

Here are snippets of my files.

driver.cpp:
code:
#include "Comparator.h"
int main()
{
  Comparator comp1(1,2);
  return 0;
}
Comparator.h:
code:
class Comparator
{
public:
  Comparator(int topInput, int bottomInput);

private:
  int top;
  int bottom;
};
Comparator.cpp:
code:
#include "Comparator.h"

Comparator::Comparator(int topInput, int bottomInput)
{
  top = topInput;
  bottom = bottomInput;
}
Notice that I want to create a Comparator object comp1 with top=1 and bottom=2.



I find out later that I actually want to initialize top and bottom to be topInput-1 and topInput-2 so I do a small change to Comparator.cpp:
code:
#include "Comparator.h"

Comparator::Comparator(int topInput, int bottomInput)
{
  top = topInput-1;
  bottom = bottomInput-1;
}
I rebuild the entire project and run this code again. However, it still reads the constructor definition the same as before with top = topInput and bottom = bottomInput. Not until I created an entirely new project and rebuilt everything from scratch that I finally got it to recognize the change in Comparator.cpp.

Tomed2000 fucked around with this message at 17:46 on Apr 9, 2009

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply