p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Ivor Horton's Beginning Visual C++ 2005 (http://p2p.wrox.com/forumdisplay.php?f=249)
-   -   CH 9 error code city (http://p2p.wrox.com/showthread.php?t=59055)

shade cat June 13th, 2007 10:34 PM

CH 9 error code city
My code matches the book and 571974 file yet here is what I get.

1>------ Build started: Project: Ex9_01, Configuration: Debug Win32 ------
1>c:\aaaaaa\visual studio\ex9_01\ex9_01\candybox.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\aaaaaa\visual studio\ex9_01\ex9_01\candybox.h(13) : warning C4183: 'CCandyBox': missing return type; assumed to be a member function returning 'int'
1>c:\aaaaaa\visual studio\ex9_01\ex9_01\candybox.h(14) : error C2523: 'CCandybox::~CCandyBox' : destructor tag mismatch
1>c:\aaaaaa\visual studio\ex9_01\ex9_01\ex9_01.cpp(13) : error C2065: 'CCandyBox' : undeclared identifier
1>c:\aaaaaa\visual studio\ex9_01\ex9_01\ex9_01.cpp(13) : error C2146: syntax error : missing ';' before identifier 'myCandyBox'
1>c:\aaaaaa\visual studio\ex9_01\ex9_01\ex9_01.cpp(13) : error C2065: 'myCandyBox' : undeclared identifier
1>c:\aaaaaa\visual studio\ex9_01\ex9_01\ex9_01.cpp(14) : error C2146: syntax error : missing ';' before identifier 'myMintBox'
1>c:\aaaaaa\visual studio\ex9_01\ex9_01\ex9_01.cpp(14) : error C3861: 'myMintBox': identifier not found
1>c:\aaaaaa\visual studio\ex9_01\ex9_01\ex9_01.cpp(20) : error C2070: ''unknown-type'': illegal sizeof operand
1>c:\aaaaaa\visual studio\ex9_01\ex9_01\ex9_01.cpp(22) : error C2070: ''unknown-type'': illegal sizeof operand
1>Build log was saved at "file://c:\AAAAAA\Visual Studio\Ex9_01\Ex9_01\Debug\BuildLog.htm"
1>Ex9_01 - 9 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Any ideas?

shade cat June 14th, 2007 02:09 AM

Could there be a setting in Visual Studio 8 that might be causing this?
Mabe a linker, incude file, or debug setting.
When I was working on sketcher I would get only one or two errors that I could fix and then on the third compile I got 284 errors. The errors don't make any sense to me. Has the language changed sinse I baught this book?
I have a hunch it might have something to do with include files and Microsoft DirectX SDK (February 2007)which I installed prior to installing Visual Studio 8. Maybe VS 8 is looking in the wrong place for include files.

Here is my code try it yourself and see if you get the same errors.

// Header filr box.h in project Ex9_01
#pragma once

class CBox
    double m_Length;
    double m_Width;
    double m_Height;

    CBox(double lv = 1.0, double wv = 1.0, double hv = 1.0):
    m_Length(lv), m_Width(wv), m_Height(hv){}

// Header file CandyBox.h in project Ex9_01
#pragma once
#include "box.h"
class CCandybox: CBox
    char* m_Contents;

    CCandyBox(char* str = "Candy") // Constructor
        m_Contents = new char[ strlen(str) + 1 ];
        strcpy_s(m_Contents, strlen(str) + 1, str);
    { delete[] m_Contents; };

// Ex9_01.cpp
// Using a derived class
#include <iostream> // For stream I/O
#include <cstring> // For strlen() and strcpy()
#include "CandyBox.h" // For CBox and CCandyBox
using std::cout;
using std::endl;

int main()
  CBox myBox(4.0, 3.0, 2.0); // Create CBox object
  CCandyBox myCandyBox;
  CCandyBox myMintBox("Wafer Thin Mints"); // Create CCandyBox object

  cout << endl
       << "myBox occupies " << sizeof myBox // Show how much memory
       << " bytes" << endl // the objects require
       << "myCandyBox occupies " << sizeof myCandyBox
       << " bytes" << endl
       << "myMintBox occupies " << sizeof myMintBox
       << " bytes";

  cout << endl
       << "myBox length is " << myBox.m_Length;

  myBox.m_Length = 10.0;

  // myCandyBox.m_Length = 10.0; // uncomment this for an error

  cout << endl;
  return 0;

Dan6 July 15th, 2007 09:29 AM

Hi shade cat,

It's been a while since you posted this so you might've already solved it by now. So sorry if I'm telling you something you already know.

I think what's causing the problem is just a little typo. In your CandyBox.h file you have the line "class CCandybox: CBox". This should be "class CCandyBox: CBox" - a captial "B" for the 'box' in CandyBox. If you make this tiny correction I think it will compile fine.

Hope this helps.


shade cat July 20th, 2007 01:55 PM

Thanks for the help. Your the first person to reply to one of my questions. I was beginning to think this site was a ghost town. I can't remember if I solved this one or not. I have been jumping around reading four different programming books and I just ordered no. 5 in attempt to understand this language. I will be coming back to this section to review in 2 or 3 weeks. Your help is much appreciated

All times are GMT -4. The time now is 08:18 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.