| | |
HELP writing structure and class definition - Visual C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2005
Posts: 7
Reputation:
Solved Threads: 0
My assignment is to create a definition of the class Box and a structure definition.
The class definition needs the following:
Data Member Data Type
boxNumber int
boxType int
boxLength float
boxWidth float
boxHeight float
boxArea float
boxCost float
boxPrice float
boxProfit float
boxFile fstream //Dont include boxFile yet.
Member Functions
setBoxFile - sets the boxFile reference variable.
addBox - Adds a new box to the box file.
findBox - Updates records in the box file.
updateBox
and a get and set function for each of the class attributes.
My teacher said not to worry about the Member Functions yet. Not covered.
I used an example of a class called Time that i found in my textbook.
the set function example:
void setTime( int, int, int);
Im pretty sure i defined the get and set functions in the right way. Im confused about how using upper and lower case in the class and structure makes a difference.
i tried to create a file to test it in but i dont know what im doing wrong.
It showed 3 errors:
main.cpp
(21) : warning C4761: integral size mismatch in argument; conversion supplied
main.obj : error LNK2001: unresolved external symbol "public: int __thiscall Box::getBoxType(void)" (?getBoxType@Box@@QAEHXZ)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Box::setBoxType(int)" (?setBoxType@Box@@QAEXH@Z)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall Box::Box(void)" (??0Box@@QAE@XZ)
Debug/main.exe : fatal error LNK1120: 3 unresolved externals
The class definition needs the following:
Data Member Data Type
boxNumber int
boxType int
boxLength float
boxWidth float
boxHeight float
boxArea float
boxCost float
boxPrice float
boxProfit float
boxFile fstream //Dont include boxFile yet.
Member Functions
setBoxFile - sets the boxFile reference variable.
addBox - Adds a new box to the box file.
findBox - Updates records in the box file.
updateBox
and a get and set function for each of the class attributes.
My teacher said not to worry about the Member Functions yet. Not covered.
I used an example of a class called Time that i found in my textbook.
the set function example:
void setTime( int, int, int);
Im pretty sure i defined the get and set functions in the right way. Im confused about how using upper and lower case in the class and structure makes a difference.
C++ Syntax (Toggle Plain Text)
#ifndef BOX_CLASS #define BOX_CLASS struct BoxData { int boxNumber; // Allow for up to 100 boxes int boxType; // box type (1 to 4). float boxLength; float boxWidth; float boxHeight; }; // end struct Box class Box { public: //boxdata Box( ); // constructor function //sets BoxData variables. void setBoxNumber(int); void setBoxType(int); void setBoxLength(float); void setBoxWidth(float); void setBoxHeight(float); //gets BoxData ( 5 variables) and (4 functions) - used to return values. int getBoxNumber(); int getBoxType(); float getBoxLength(); float getBoxWidth(); float getBoxHeight(); float getboxArea(); float getboxCost(); float getboxPrice(); float getboxProfit(); bool findBox(int); // Finds a particular box in the box file. void setBoxFile(int); // sets the boxFile reference variable. bool addBox(int); // Adds a new box to the box file. bool updateBox(int); // Updates records in the box file. //boxFile fstream private: float boxArea; float boxCost; float boxPrice; float boxProfit; }; //end class Box #endif //main.cpp starts here #include <iostream> using std::cin; using std::cout; using std::endl; #include "Box.h" //include definition of class int main () { Box x; // instantiate object x of class Box x.setBoxType(1); x.setBoxType(2); x.setBoxType(3); cout << "Choose a box type between ( 1 - 4 ) or 0 to exit: " << x.getBoxType; return 0; }
i tried to create a file to test it in but i dont know what im doing wrong.
It showed 3 errors:
main.cpp
(21) : warning C4761: integral size mismatch in argument; conversion supplied
main.obj : error LNK2001: unresolved external symbol "public: int __thiscall Box::getBoxType(void)" (?getBoxType@Box@@QAEHXZ)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Box::setBoxType(int)" (?setBoxType@Box@@QAEXH@Z)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall Box::Box(void)" (??0Box@@QAE@XZ)
Debug/main.exe : fatal error LNK1120: 3 unresolved externals
•
•
Join Date: Apr 2005
Posts: 63
Reputation:
Solved Threads: 1
Did you define the member functions? That looks like the problem to me...
something like:
something like:
C++ Syntax (Toggle Plain Text)
Box::Box() { //my constructor code here }
![]() |
Similar Threads
- Can't update a textbox in Visual C++ (C++)
- How Do I . . . Make a Class Accessible from a DLL (C++)
- How to use VB6 class module in Visual Studio 2005 (VB.NET)
- String declaration in class definition (C)
- writing structure to disk in c++ (C++)
- unresolved external symbol when using a hashtable class (C++)
- writing a class without the class declaration? (C++)
- Classes (C++)
Other Threads in the C++ Forum
- Previous Thread: file save load problems
- Next Thread: Newbie needs help with mortgage program
Views: 7472 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





