Object decleration problem

+1 sowmyaraj g · June 10, 2015
I am following c++ tutorials in tutorial 42,43 iam getting an error while declearing object in classes
i decleared as:sally so;
Please help me in rectifing my mistake.

Post a Reply

Replies

Oldest  Newest  Rating
0 Dol Lod · June 11, 2015
Just paste the code you have. It should be trivial to debug.
0 sowmyaraj g · June 11, 2015
I created a class named sally.
in main.cpp:
Int main(){
Sally sally object;
Sally object.print();
Sally*sallypointer=&sally object;
Sally pointer->print();
}
In sally.h:
#ifndef sally_h
#define sally_h
class sally
{
Public:
Sally();
Void print();
Protected:
Private:
};
In sally.cpp:
#include"sally.h"
#include<iostream>
Using namespace std;
Sally::sally()
{
}
Void sally::print(){
Cout<<"stone age"<<endl;
}
Please give me a solution.
0 Dol Lod · June 12, 2015
The main problems are capitalization, not including sally.h in main.cpp and forgetting the #endif in the header file. Capitalization is case sensitive: IF is different than if. 

File names are also case sensitive.

Void->void
Int->int 

...

Multiple problems I see is in sally.h:

1)You forgot the #endif at the end of the header file. 

2) I'm not sure if your spelling is a typo or not but C++ is case sensitive. Sally is not the same as sally. Is sally the name of the class or Sally? Public, private and protected should be lowercase. 

In Sally.cpp, using should be lowercase and cout should be lowercase. Void should also be lower case. 

3) In main.cpp, you are never including sally.h. Additionally, to use a method, the object must actually be created.

After fixing capitalization and the rest it should be clear.

I can show you what it should look like.

I don't know what language you started with, but please review the very fundamentals. Some of these issues are pretty big. 

In main.cpp:

#include "Sally.h"

int main()
{
Sally object;
object.print();
Sally* sallypointer=&object;
sallypointer->print();
}

In Sally.h

#ifndef SALLY_H
#define SALLY_H

class Sally
{
public:
Sally();
void print();
protected:
private:
};

#endif

In Sally.cpp:
#include <iostream>
#include "Sally.h"

using namespace std;

Sally::Sally()
{
}

void Sally::print()
{
cout<<"stone age"<<endl;
}
  • 1

C++

107,198 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator