AKMafia001's Profile
Reputation: 135
Stalwart
- Group:
- Active Members
- Active Posts:
- 457 (0.62 per day)
- Joined:
- 11-June 11
- Profile Views:
- 2,933
- Last Active:
Jun 04 2013 10:20 AM- Currently:
- Offline
Previous Fields
- Country:
- Who Cares
- OS Preference:
- Windows
- Favorite Browser:
- FireFox
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- PC
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Latest Visitors
-
rgfirefly24 
06 May 2013 - 07:32 -
sepp2k 
17 Feb 2013 - 07:46 -
raghav.nagana... 
13 Feb 2013 - 03:57 -
I4Irfan007 
04 Feb 2013 - 03:10 -
Sam1993 
23 Jan 2013 - 09:10 -
snoopy11 
07 Jan 2013 - 13:46 -
htoruen 
02 Jan 2013 - 20:38 -
CY5 
25 Dec 2012 - 08:51 -
supercorey 
25 Dec 2012 - 06:22 -
mikelino 
20 Dec 2012 - 07:15
Posts I've Made
-
In Topic: Why is my variable undefined
Posted 11 Jan 2013
You are having a problem with calling the base class constructor...
Read my this post in your old thread... -
In Topic: Why is my variable undefined
Posted 11 Jan 2013
The base class constructor accepts some parameters,
024 SalariedEmployee(string n, string s, double np, double w, int h, string d);
While you didn't pass any in both the cases, either you intended it to call the default constructor or one with empty parameter list which you even didn't declared... -
In Topic: Trying to understand this code
Posted 7 Jan 2013
If you don't understand the basics of C++, it is really hard to understand this code, as it contains stuff from STL and Win32 API...
Better learn C++ first...
Useful C++ links:
learncpp.com
cplusplus.com
Win32 API...
Hope this Helps! -
In Topic: Should I try to work around having to use header files?
Posted 3 Jan 2013
You cannot include .cpp files with #include, they should be header files with .h extension(maybe .hpp or .hxx too)...
But, if you want to use a function from another file, say print.cpp, you can just put a declaration of it in your file(so the compiler would know that this function exists somewhere later) and call it...
e.g.
print.cpp
#include <iostream> void printHello() { std::cout << "Hello, World!"; }
main.cpp
void printHello(); int main() { printHello(); return 0; } -
In Topic: Should I try to work around having to use header files?
Posted 3 Jan 2013
In C++, we use '.' operator to select members of an object of some struct or class type. And when that object is a pointer type, '->' is used instead... The case that you didn't find '->' operator in Java is because it doesn't have pointers...
*this is a hidden pointer inside every class member function which points to the object which called the member function... This is how C++ keeps track of which object is working with the member function...
The case that we keep class declaration in separate file and its implementation in another, and both of them in different than the main or any other is for the sake of simplicity and reusability... So we can make changes easily to our class and modify it and in future if we need to use the same class in another program then we can easily integrate it into it.
However, you can have all the stuff in one file, say in main.cpp, you can throw in your class implementation your other code and everything thing else; it will work just fine... But it will be difficult to manage and modify later...
Even you can have the implementation of the class in the header file too, say in MyClass.h, include it in main file and it will work just fine(but it is not a good programming practice)...
The rule of thumb is to have the declaration of the class in the header file, its implementation in source file .cpp and include it in your main file...
Example:
MyClass.h
#ifndef MyClass_H #define MyClass_H class MyClass { int data; public: int getData(); void setData(int); MyClass(int); }; #endif
MyClass.cpp
#include "MyClass.h" MyClass::MyClass(int data) :data(data) { } int MyClass::getData(){ return data; } void MyClass::setData(int data){ this->data = data; }
main.cpp
#include <iostream> #include "MyClass.h" int main() { MyClass myclass(4); std::cout << myclass.getData() << std::endl; myclass.setData(6); std::cout << myclass.getData() << std::endl; return 0; }
Building from and IDE is simple. But from command line, you have to compile both the files:
e.g.
g++ main.cpp myclass.cpp
Coming to your code, you have a conflict with argument lists in your header file and .cpp:
5 void setData(); 6 classType();
int data
04 void classType::setData(int data){ 07 classType::classType(int data)
And, Unlike Java, class ends with a semi-colon ; on the closing brace:
class MyClass { ... }; // <- semi-colon here
PS: What is the linker error you are talking about?
My Information
- Member Title:
- D.I.C Regular
- Age:
- 22 years old
- Birthday:
- January 2, 1991
- Gender:
-
- Interests:
- Computers, Programming, Games, Sports, Cooking, Swimming
- Full Name:
- Mafia
- Years Programming:
- 6
- Programming Languages:
-
BASIC
C/C++
SQL
Assembly (80x86)
Java
PHP
Javascript
C#
Contact Information
- E-mail:
- Private
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
vaseeprasanna
18 Dec 2012 - 08:29vaseeprasanna
18 Dec 2012 - 08:28AKMafia001
09 Dec 2012 - 12:04Xupicor
09 Dec 2012 - 10:24raghav.naganathan
09 Dec 2012 - 09:26AKMafia001
07 Dec 2012 - 03:15raghav.naganathan
07 Dec 2012 - 02:56raghav.naganathan
05 Dec 2012 - 10:29Looks like you are up in line for the expert badge :)
techdreamer
04 Nov 2012 - 06:59