3 Replies - 5424 Views - Last Post: 06 August 2010 - 11:02 AM Rate Topic: -----

#1 CasGrimes  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 97
  • Joined: 09-March 10

Namespace/class name problem

Posted 06 August 2010 - 09:21 AM

I'm currently reading through "accelerated C++" so I'm sure a majority of you have seen this exercise before.

The idea of the exercise is to create a frame window when outputting the users name.

In the book the exercise takes place in the main cpp file, but I like to get into a OO mindset when making programs so I tried to change this exercise accordingly.

The errors I get say:
Error 1 error C2653: 'NonLoopGreeting' : is not a class or namespace name
Warning 2 warning C4305: 'argument' : truncation from 'int' to 'char'
Warning 3 warning C4309: 'argument' : truncation of constant value
IntelliSense: name followed by '::' must be a class or namespace name

Below is the code.

NonLoop_fGreeting.h
#ifndef NONLOOP_FGREETING_H
#define NONLOOP_FGREETING_H

class NonLoopGreeting
{
public:
	void nlGreeting();
};

#endif



NonLoop_fGreeting.cpp
#include <string>
#include <iostream>
using namespace std;

void NonLoopGreeting::nlGreeting()
{
	cout << "Please enter your first name: " << endl;
	string name;
	cin >> name;

	// Build message that I intend to write.
	const string greeting = "Hello, " + name + "!";

	// Builds 2nd and 4th line of the framed window.
	const string spaces(greeting.size(), ' ');
	const string second = "* " + spaces + " *";

	// Builds 1st and 5th line of the framed window.
	const string first(second.size(), ' *');

	cout << endl;
	cout << first << endl;
	cout << second << endl;
	cout << "* " << greeting << " *" << endl;
	cout << second << endl;
	cout << first << endl;
}



Main.cpp
#include "NonLoop_fGreeting.h"

int main()
{
	NonLoopGreeting nonLoop;

	nonLoop.nlGreeting();

	return 0;
}



The errors mostly point to line 5 of the NonLoop_fGreeting.cpp file.

Any help is greatly appreciated.

This post has been edited by CasGrimes: 06 August 2010 - 09:22 AM


Is This A Good Question/Topic? 1
  • +

Replies To: Namespace/class name problem

#2 athlon32  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 116
  • View blog
  • Posts: 363
  • Joined: 20-August 08

Re: Namespace/class name problem

Posted 06 August 2010 - 09:45 AM

The error is telling you that the compiler has no idea what NonLoopGreeting is. You need to include NonLoop_fGreeting.h in NonLoopGreeting.cpp so it can identify what it is defining :)

Hope I helped :D

== EDIT: typos ==

This post has been edited by athlon32: 06 August 2010 - 09:46 AM

Was This Post Helpful? 2
  • +
  • -

#3 CasGrimes  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 97
  • Joined: 09-March 10

Re: Namespace/class name problem

Posted 06 August 2010 - 09:47 AM

View Postathlon32, on 06 August 2010 - 08:45 AM, said:

The error is telling you that the compiler has no idea what NonLoopGreeting is. You need to include NonLoop_fGreeting.h in NonLoopGreeting.cpp so it can identify what it is defining :)

Hope I helped :D

== EDIT: typos ==

That's really embarassing. Thank you for the help and I guess I won't make this mistake again :$
Was This Post Helpful? 0
  • +
  • -

#4 sungchoiok  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 44
  • View blog
  • Posts: 140
  • Joined: 18-July 10

Re: Namespace/class name problem

Posted 06 August 2010 - 11:02 AM

I'm no moderator or anything (actually, a New DIC Head), but I gott say: wow... this has to be a prime-example of how every thread should look like.

I see so much arrogant, master-slave-type questioning, etc., lately... this is heaven!

:)

This post has been edited by sungchoiok: 06 August 2010 - 11:05 AM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1