trouble with const functions inside class header

Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "stdafx.h"
#include <iostream>
#include "arrow.h"

using namespace std;

int main()
{
	arrow arrowobj;
	arrowobj.printstuff();

	const arrow conarrow;
	conarrow.printthiscon();

	cin.get();
	cin.get();
	return 0;
};


Arrow.h
1
2
3
4
5
6
7
8
9
#pragma once
ref class arrow
{
public:
	arrow(void);
	void printstuff();
	void printthiscon() const;

};


Arrow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "StdAfx.h"
#include <iostream>
#include "arrow.h"


arrow::arrow(void)
{
}

void arrow::printstuff()
{
	std::cout << "call of printstuff function. " << std::endl;

};

void arrow::printthiscon() const
	{
		std::cout << "this is constant" << std::endl;
	}


1>------ Build started: Project: testprograms, Configuration: Debug Win32 ------
1>  arrow.cpp
1>c:\documents and settings\xxxx\desktop\prog proj\testprograms\testprograms\arrow.h(7): error C3842: 'printthiscon': 'const' and 'volatile' qualifiers on member functions of managed types are not supported
1>arrow.cpp(17): error C3842: 'printthiscon': 'const' and 'volatile' qualifiers on member functions of managed types are not supported
1>  testprograms.cpp
1>c:\documents and settings\xxxx\desktop\prog proj\testprograms\testprograms\arrow.h(7): error C3842: 'printthiscon': 'const' and 'volatile' qualifiers on member functions of managed types are not supported
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


What am I doing wrong?

edit: I corrected type and updated output, still getting error.
edit: new updates.
Last edited on
closed account (10oTURfi)
You are missing () at line 23

Should be arroww.printthiscon();
Yeah I caught that but then I put it into my header and it came up completely different errors.
There is a typo in the object name

const arrow conarrow;
conwarrow.printthiscon();
Corrected that but still getting error
Show your updated code.

I only now have seen that you are using managed code

ref class arrow


Then what is the problem?! The error message is very clear.

arrow.h(7): error C3842: 'printthiscon': 'const' and 'volatile' qualifiers on member functions of managed types are not supported


You shall read error messages and not bother other members of forum.
Last edited on
Maybe the terminator after the closing brace of the printstuff() declaration?

Not sure if that'll matter to be honest.
Last edited on
No when they're placed there the semi colons aren't needed but don't do any harm if they're there.
Right now it's at the most updated code.
Sorry, I didn't know that ref class arrow was managed code, this is the beginner section of the forum not the advanced debugger section. I am a beginner and this is a beginner error. Thank you for your help, and I wasn't aware that managed code such as that causes error.
Last edited on
Sorry, I didn't know that red class arrow was managed code, this is the beginner section of the forum not the advanced debugger section. I am a beginner and this is a beginner error. Thank you for your help, and I wasn't aware that managed code such as that causes error.

Personally don't think you have anything to apologise for.

You're right, this is the beginners forum. Therefore, I think more experienced members should exercise some tact when they seem something that looks easy to them as it's probably not obvious to the poster. Given the number of homework requests and half-baked coding efforts we get on here, I'd say that this was an entirely reasonable query.

Moreover, compiler errors messages are often cryptic and ambiguous, especially to a beginner.
Last edited on
@bleachy: Ignore forum members that have the attitude like vlad from moscow. I remember all too well when I started 14 years ago how hard it was to understand the errors. As a beginner I know the error
'printthiscon': 'const' and 'volatile' qualifiers on member functions of managed types are not supported
would have made no sense to me. iHutch105 is right in this is the beginner forum and as such is where you should have posted this question.

I'd recommend using the tutorials on this site to learn from ( http://cplusplus.com/doc/tutorial/ ) as they don't use Managed C++.

@iHutch105: That tact from a person speaks more to their people skills than their experience to me.

[EDIT]
@bleachy: Also, like iHutch105 said, never apologize for looking for help. As a beginner you are entitled to have issues and, like iHutch105 pointed out, a lot of the experienced programmers have forgotten what it was like to start out in programming.
Last edited on by closed account z6A9GNh0
I appreciate your feed back after he reluctantly explained what managed code was I figured it out and removed ref and it worked. I learned from it so it's all cool. Also the sorry was more sarcastic. Thank you for your support this is definitively one of the best communities for programming there is that I've come across and I appreciate every ones time.
Topic archived. No new replies allowed.