By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,646 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,646 IT Pros & Developers. It's quick & easy.

Error with the following code

P: n/a
I am having some issues with the following code, basically what I am
trying to do, is familierise myself with compiler warnings, when I try
to access a private or protected class function.
Here is the errors the compiler generates:

ex1.cpp: In function `int main()':
ex1.cpp:12: error: `testing' is not a class or namespace
ex1.cpp:12: error: `pubtest' undeclared (first use this function)
ex1.cpp:12: error: (Each undeclared identifier is reported only once for
each function it appears in.)
ex1.cpp:13: error: `testing' is not a class or namespace
ex1.cpp:13: error: `pritest' undeclared (first use this function)
ex1.cpp:14: error: `testing' is not a class or namespace
ex1.cpp:14: error: `protest' undeclared (first use this function)
test.cpp:1:24: ex1-Header.h: No such file or directory
test.cpp:4: error: `Test' has not been declared
test.cpp:9: error: `Test' has not been declared
test.cpp:14: error: `Test' has not been declared
Here is the code:
###ex1-Header.h
class Test {
public:
void pubtest();
private:
void pritest();
protected:
void protest();
};

###test.cpp

#include <ex1-Header.h>
#include <iostream>

void Test::pubtest() {
std::cout << "Public Test" << std::endl;
}
void Test::pritest() {
std::cout << "Private Test" << std::endl;
}
void Test::protest() {
std::cout << "Protected Test" << std::endl;
}

###ex1.cpp
#include "ex1-Header.h"
#include <iostream>

using namespace std;

int main() {
Test testing;
testing::pubtest();
testing::pritest();
testing::protest();

return 0;
}

I did expect compiler errors when trying to access the private and
protected functions, however even when I comment out the calls to these
functions the compiler still issues warnings.
Can anyone point me in the correct direction of where I am going wrong.
Thanks
--
Materialised
perl -e 'printf %silto%c%sal%c%s%ccodegurus%corg%c, ma, 58, mw, 107,
'er', 64, 46, 10;'
Bart: "What if you're a really good person, but you get into a really,
really bad fight and your leg gets gangrene and it has to be amputated.
Will it be waiting for you in heaven?"
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Le lundi 2 mai 2005 à 13:20:50, Materialised a écrit dans
comp.lang.c++*:
I am having some issues with the following code, basically what I am
trying to do, is familierise myself with compiler warnings, when I try
to access a private or protected class function.
Here is the errors the compiler generates:

ex1.cpp: In function `int main()':
ex1.cpp:12: error: `testing' is not a class or namespace
[snip]
Test testing;
testing::pubtest();
testing::pritest();
testing::protest();

return 0;
}

I did expect compiler errors when trying to access the private and
protected functions, however even when I comment out the calls to these
functions the compiler still issues warnings.
Can anyone point me in the correct direction of where I am going wrong.
Thanks


The compilder did: `testing' is not a class or namespace. '::' applies
to a class or a namespace, not an object.

testing.pubtest();
testing.pritest();
testing.protest();

--
___________ 02/05/2005 13:25:10
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Il faut donc que les hommes commencent
-'(__) par n'être pas fanatiques pour mériter
_/___(_) la tolérance. -- Voltaire, 1763
Jul 23 '05 #2

P: n/a
Materialised wrote:
I am having some issues with the following code, basically what I am
trying to do, is familierise myself with compiler warnings, when I try
to access a private or protected class function.
Here is the errors the compiler generates:

ex1.cpp: In function `int main()':
ex1.cpp:12: error: `testing' is not a class or namespace
ex1.cpp:12: error: `pubtest' undeclared (first use this function)
ex1.cpp:12: error: (Each undeclared identifier is reported only once for
each function it appears in.)
ex1.cpp:13: error: `testing' is not a class or namespace
ex1.cpp:13: error: `pritest' undeclared (first use this function)
ex1.cpp:14: error: `testing' is not a class or namespace
ex1.cpp:14: error: `protest' undeclared (first use this function)
test.cpp:1:24: ex1-Header.h: No such file or directory
test.cpp:4: error: `Test' has not been declared
test.cpp:9: error: `Test' has not been declared
test.cpp:14: error: `Test' has not been declared
Here is the code:
###ex1-Header.h
class Test {
public:
void pubtest();
private:
void pritest();
protected:
void protest();
};

###test.cpp

#include <ex1-Header.h>
#include <iostream>

void Test::pubtest() {
std::cout << "Public Test" << std::endl;
}
void Test::pritest() {
std::cout << "Private Test" << std::endl;
}
void Test::protest() {
std::cout << "Protected Test" << std::endl;
}

###ex1.cpp
#include "ex1-Header.h"
#include <iostream>

using namespace std;

int main() {
Test testing;
testing::pubtest();
testing::pritest();
testing::protest();

return 0;
}

I did expect compiler errors when trying to access the private and
protected functions, however even when I comment out the calls to these
functions the compiler still issues warnings.
Can anyone point me in the correct direction of where I am going wrong.
Thanks

My bad, I should have been using object.method();
Thanks Anyway.

--
Materialised
perl -e 'printf %silto%c%sal%c%s%ccodegurus%corg%c, ma, 58, mw, 107,
'er', 64, 46, 10;'
Homer: "Ha ha! Look at this country! ? R U Gay!? Ha ha!" (looking at
Uruguay on the globe)
Jul 23 '05 #3

P: n/a
MJ
Hi
Nothing you have to access the object using the . operatore instead of
scope resolution operator

check it below
#include <iostream>

using namespace std;
class Test {
public:
void pubtest();
private:
void pritest();
protected:
void protest();

};

void Test::pubtest() {
std::cout << "Public Test" << std::endl;
}

void Test::pritest() {
std::cout << "Private Test" << std::endl;
}

void Test::protest() {
std::cout << "Protected Test" << std::endl;

}
int main() {
Test testing;
testing.pubtest();
//testing::pubtest();
// testing.pritest();
// testing::protest();

return 0;

}

MJ

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.